Issue with a non-greedy quantifier


#1

Hi!

I have a source text that contains two variables in square brackets. I would like to match both of them but only them without the text between. I’ve been always using the “non-greedy” quantifier for such purposes and also here I’ve used it:
\[(.*?)\]

And from what I expect it should be OK but it matches the same as if I wouldn’t use the “?” (which makes the quantifier non-greedy). So it matches the same as \[(.*)\]

image

As you can see I’ve used the same regexp as in xBench. Am I not aware of something or is it a program issue? Can you help me solving this?

Thank you in advance for any comment on this!


#2

Xbench uses POSIX Regex, which does not have the non-greedy operator in PERL or .NET flavors.

Therefore with this Regex flavor you must make your expression non-greedy like this:

\[[^\[]*\]

That said, with regards to highlighting, currently in Regex mode there is only highlighting of the first match (i.e. the match that makes the segment to be part of the search results), although this will be changed in the future to show all matches in the segment.


#3

Thank you very much for your help! This explains the issue. I’ve tested it and it works, thanks!