0

Hello I have a URL string:

'http://www.hello.com/index.php?page=11'

What is the regular expression that I have to execute to get the page number?

Matan Yadaev
  • 3,018
  • 3
  • 19
  • 21

2 Answers2

0
(\d+)[^\d]*$

Try this.Grab the capture.See demo.

http://regex101.com/r/wQ1oW3/10

vks
  • 67,027
  • 10
  • 91
  • 124
0

Use capturing group to capture one or more digits which are present just after to ?page=.

> var s = 'http://www.hello.com/index.php?page=11'
undefined
> var re = /\?page=(\d+)/;
undefined
> console.log(re.exec(s)[1])
11
> var re = /\bpage=(\d+)/;
undefined
> console.log(re.exec(s)[1])
11
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274