Using this regex /var userId = (\d+)/
, I can find the id of the user. Except it returns "var userId = 117051"
instead of just 117051. I looked around in regexr but I'm not very good with regex. Is there a way to only get the id?
Asked
Active
Viewed 471 times
0

Hugo
- 349
- 3
- 6
- 23
-
Are you parsing javascript with regexp? – Shilly Jul 24 '19 at 15:15
-
1Extract the value from the first capturing group. `var match = myRegexp.exec(myString); console.log(match[1]);` – wp78de Jul 24 '19 at 15:16
-
@Shilly I'm using regex in javascript – Hugo Jul 24 '19 at 15:16
-
Your regex already works correctly. You just need to access Group 1 value using the right code. – Wiktor Stribiżew Jul 24 '19 at 15:17
1 Answers
2
string = "some string containing var userId = 117051";
var foundId = string.match(/var userId = (\d+)/)[1];
console.log(foundId); // "117051"

DenverCoder1
- 2,253
- 1
- 10
- 23