I have lines that start with a number followed by a space, a key and then the value. I need only the value. The problem is that my regex returns the HOLE line instead of only the value.
lines example:
1 NAME Bob /Cox/
1 SEX M
1 FAMS @F1@
regex:
/^(?=1\s[\w]*\s)[\w\W\s]*/
Did i misunderstood how "positive lookahead" works?
The regex you are you are using it first checks using lookahead((?=1\s[\w]*\s)
) whether a certain pattern is available or not upfront. It doesn't mean that it is skipping these matches. Its only checking it's existence. Which means your next portion of regex still starts exactly after the start of string(^
).
For your particular this case you can use replace
instead of regex matching:
var input = '1 NAME Bob /Cox/\n1 SEX M\n1 FAMS @F1@';
input = input.replace(/^1\s[\w]*\s/mg, "");