Regex for this excludes matches in quotes

I am working on this rather large refactoring project and I am using intellij find / replace with regexp to help me.

This is the regex that I use:

\b(?<!\.)Units(?![_\w(.])\b

I find that most matches that are not useful for my purpose are matches with strings inside quotes, for example: "units"

I would like to find a way so that the above expression does not match when it finds the corresponding string that is enclosed between quotation marks ...

thanks in advance, this is a rock place!

+3
source share
2 answers

, , , :

^([^"]*("[^"]*")*[^"]*)*\b(?<!\.)Units(?![_\w(.])\b([^"]*("[^"]*")*[^"]*)*$

,

([^"]*("[^"]*")*[^"]*)*

. , .

, .

+2

Intellij Java regexes, ? :

(?m)(?<![\w.])Units(?![\w(.])(?=(?:[^\r\n"\\]++|\\.)*+[^\r\n"\\]*+$)

:

(?<![\w.])Units(?![\w(.])

\b , lookbehind lookahead () \w, . lookahead , ( ) :

(?=(?:[^\r\n"\\]++|\\.)*+[^\r\n"\\]*+$)

, , Welbog, , , . . Intellij find/replace , ? , ?

+1

Source: https://habr.com/ru/post/1714329/


All Articles