How to find a all string in ' but exclude lines which contain a System.debug

Viewed 41

I trying to get all data inside ' using this

['].*?[']

and additionaly i want to exclude lines which is contain System.Debug

i tried

^((?!System.debug).)*$['].*?[']

but this is not working , what i doing wrong ?

1 Answers

You can use

(?<!System\.debug.*)'(?!.*System\.debug)[^']*'

See the regex demo and the Visual Studio Code demo & settings:

enter image description here

Details:

  • (?<!System\.debug.*) - a negative lookbehind that fails the match if there is System.debug and any zero or more chars other than line break chars as many as possible immediately to the left of the current location
  • ' - a ' char
  • (?!.*System\.debug) - a negative lookahead that fails the match if there is any zero or more chars other than line break chars as many as possible and then System.debug immediately to the right of the current location
  • [^']* - zero or more chars other than '
  • ' - a ' char.

NOTE: In VSCode regex, [^'] and other negated character classes only match line breaks if there is \r or \n somewhere in the regex pattern, so it is not necessary to use [^'\n], but it is used in the regex101 demo.

Related