Regular expression for match sentences not starts with specified prefix

221 Views Asked by At

I would like to find strings in double quotes but only if they used outside of call of specified function foo. For example:

foo("some str1"); // ignore
foo2("another string"); // need this
"simple string"; // need this
foo(L"wide str"); // ignore
#define NAME "name" // need this
int i = foo("must be ignored"); // ignore

I have tried \b(?!foo\()L?"[^"]*"\b from this answer, but it doesn't work correct. Used end double quote on one line as begin on another. Like this "); // ignore<CR> foo2("

If I suppose I should include possessive quantification. To substring not satisfying excluded completely from further search. But don't know how to do it correctly.

It is required to search for files in the Embarcadero RAD Studio XE, but satisfied with any decision in the Perl regexp syntax.

Important: wants to find all occurences of double quoted strings outside of foo function. And not to be distracted by a string inside the foo.

2

There are 2 best solutions below

5
Cyrbil On

You can try it here: https://regex101.com/r/mG7gP7/1 I match two scenario

  • Search for function not name foo, and match the string inside quotes.
  • Any text inside quotes where there is no function call
0
ryuichiro On

What do you think about this one?

/(^(?!foo\()|\)).*"(.*)"/gm