I need to match any characters before the first encountered specific character. Tried:
use feature 'say';
say $1 if 'bla-bla if (func(arg1, arg2) < 0) {' =~ /func\s*\((.*?)\)\s*\{/;
I assumed that there will be no output for this code, cause the .*?
matches arg1, arg2
(i.e. before the nearest )
) and there is no {
after func(arg1, arg2)
so the regex turns to false. However, the output was arg1, arg2) < 0
. Indeed, non-greedy regex chooses as few as needed to allow the overall pattern to match. But I want this regex to be false with such strings. I found in that post the working solution. In my case the .*?
should be changed to [^\)]*
. But is there any other ways to do it? Thanks for any clarifications and examples. Sorry if this is obvious