Stop regex from reaching inappropriate content

I need to extract a series of meaningful values ​​from a file. The basic template for the values ​​I need to map looks like this:

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

Unfortunately, in places it covers quite a lot of content to get a true match, and the lazy quantifier (?) Is not as lazy as we would like.

How to change the above so that from the following:

"indicator.value here" [false], "other content", "more other content", "does not match this because there is no full stop" [true], "indicator.this value I want to match" [true]

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

Currently, this entire line is being returned by my previous regular expression.

+5
source share
3 answers

Assuming the commas are a separator - just avoid matching with them:

 @"""indicator\.[^,]+?""\[true\]" 
+1
source

Try using "indicator\.(.*)?"\[true\] instead and see if that helps. I think lazy only applies to the * operator. I vaguely remember this question a few years ago.

0
source

You can use the reset technique by discarding a pattern that you do not want. So you might have something like this:

 "indicator\..+?"\[false\]|"indicator\.(.+?)"\[true\] Discard this pattern --^ Capture this --^ 

Working demo

Match Info

 MATCH 1 1. [150-182] `this is the value I want matched` 
0
source

All Articles