I need to extract the middle number from this using regex:
/166012342170/934760332134/794294808150/2436280815794/
Needed output: 934760332134
I tried using this: (?:.+?/){2}
I am new to regex :(
I need to extract the middle number from this using regex:
/166012342170/934760332134/794294808150/2436280815794/
Needed output: 934760332134
I tried using this: (?:.+?/){2}
I am new to regex :(
In JS, you may simply split the string with /
char:
console.log('/166012342170/934760332134/794294808150/2436280815794/'.split('/')[2])
If you plan to use regex you may use
var s = '/166012342170/934760332134/794294808150/2436280815794/';
var m = s.match(/^\/[^\/]+\/([^\/]+)/);
if (m) {
console.log(m[1]);
}
Details
^
- start of string\/
- a /
char[^\/]+
- 1+ chars other than /
\/
- a /
char([^\/]+)
- Capturing group 1: 1+ chars other than /
To get that second number, the regex would be
(?:\/([0-9]+)){2}
which gives 934760332134 from the line below,
/166012342170/934760332134/794294808150/2436280815794
Try it on here.