This question already has an answer here:
I am a little confused by the behaviour of the match
method on javascripts string
type.
I have a string containing:
<num> Number: 401
<title> foreign minorities, Germany
Now I want to parse 401
out of it using this regex:
/(Number: )(\d+)/g
This should give me two groups whereas the seconds should contain 401.
Trying this in node.js with this code:
const r_num = /Number: (\d+)/g;
let str = `<num> Number: 401
<title> foreign minorities, Germany `;
let res = str.match(r_num);
I am however only getting one element in my result array containing the full match rather then the two groups.
So how can I get groups rather then the full match in my result array?
via Jakob Abfalter
No comments:
Post a Comment