Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop regex from spanning across unrequired content

Tags:

c#

regex

I need to extract a series of meaningful values from a file. The basic pattern for the values I need to match looks like:

"indicator\..+?"\[true\]

Unfortunately, in places this is spanning across quite a bit of content to get a true match, and the lazy quantifier (?) is not being as lazy as I'd like.

How do I modify the above so that out of the following:

"indicator.value here"[false],"other content","more other content","indicator don't match this one because the full stop is missing"[true],"indicator.this is the value I want matched"[true]

only this value is returned: "indicator.this is the value I want matched"[true]

Currently, that whole string is being returned by my above regex.

like image 737
MidnightThoughtful Avatar asked Nov 09 '22 10:11

MidnightThoughtful


1 Answers

Assuming commas are the delimiter - simply avoid matching on them:

@"""indicator\.[^,]+?""\[true\]"
like image 105
Dave Bish Avatar answered Nov 14 '22 22:11

Dave Bish