Regex Match Value In Typescript
I am trying to extract the value of certain pattern from the text. Sample text: Test: [] subtests: [a] I want to extract the line subtests: [a] or precisely what's the data insid
Solution 1:
Here is a Working Fiddle. So the only change was to remove the captures
ie: changing (.*)
to .*
Explaining your problem..
This regex ^subtests: (.*)
has captures in it. And when you find the matches for this regex, it gives you a set of all the regex matches and then all the capture's. So the first set is subtests: []
and then the set of captures that is []
. Hence your output was subtests: [],[]
(note the ,
).
Solution 2:
Here is a live demo. Forked and modified from your source. https://jsfiddle.net/soonsuweb/aj38617b/
var data = `blur blur subtests: [] blur\nblur`;
var regex = /subtests: \[.*\]/;
var test = regex.exec(data);
alert("Op: " + test);
Post a Comment for "Regex Match Value In Typescript"