K
K
Konstantin Kazanov2015-11-12 14:43:46
JavaScript
Konstantin Kazanov, 2015-11-12 14:43:46

How to find numbers in url using javascript?

There is a page: Razdel1page01.html
How to use javascript to find out what two numbers come before .html?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Borisovich, 2015-11-12
@Ka3anow

Regular Expressions

var str = "Razdel1page01.html";
var result = str.match(/([0-9]{2})(\.html)/ );
alert(result[1]);

A
Alexander Zachinalov, 2015-11-12
@SanDiesel

var str = 'Razdel1page02.html',
    digits = str.match(/\d/g),
    result = digits.slice(digits.length-2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question