user1834033
user1834033

Reputation:

Find all double quotes between parenthesis preceded by a specific expression

Using Notepad++ I want to find all the double quotes in a string starting with expr( and ending with the nearest ), like

expr("hi","",0)

so as to replace these with single quotes, as follows

expr('hi','',0)

This string can be found several times in a longer text like

bla="asd" expr("hello","",0) something something expr("bye","",0) something "later" etc

I tried several regular expressions to no avail, like

(?<=expr\()("*?)(?=\))

I need to do this in several files, so thats why I use Notepad++.

Is this possible at all? Please help.

Upvotes: 1

Views: 513

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626950

Your regex only matches 0+ double quotes that are immediately preceded with expr( and immediately followed with ).

I suggest using the following regex:

(?:\G(?!^)\s*,\s*|\bexpr\()\s*\K"((?:[^"\\]|\\.)*)"

and replace with '$1'.

Details:

  • (?:\G(?!^)\s*,\s*|\bexpr\() - whole word expr( (\bexpr\() or the end of the previous successful match + a comma enclosed with 0+ whitespaces (\G(?!^)\s*,\s*)
  • \s* - 0+ whitespaces
  • \K - omits the text matched so far
  • " - a double quote
  • ((?:[^"\\]|\\.)*) - Group 1 capturing the double quoted string literal (0+ chars other than " and \ (with [^"\\]) or any escape sequence (\\.)
  • " - a double quote

See the screenshot:

enter image description here

Upvotes: 0

Related Questions