Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Wiktor Stribiżew for RegEx Return found Group IF String Does NOT start with ' - VSCode - Search/Replace

I suggest using

Find What:      \{\{[\s\n]*(?!['\s\n])(.*')[\s\n]*(\|[\s\n]+translate)\b
Replace With: {{ '$1 $2

See online regex demo (altered to reflect how it works in VSCode).

Image may be NSFW.
Clik here to view.
enter image description here

Details

  • ^ - start of a line
  • \{\{ - a {{ substring
  • [\s\n]* - 0+ whitespaces/linebreaks
  • (?!['\s\n]) - a negative lookahead failing the match if immediately to the right of the current location there is a ' or a whitespace (linebreak included)
  • (.*') - Capturing group 1: any 0+ chars other than line break chars, as many as possible and then a ' char
  • [\s\n]* - 0+ whitespaces/linebreaks
  • (\|[\s\n]+translate)\b - Group 2: a |, 1+ whitespaces/linebreaks and a whole word translate.

The replacement is ', Group 1 backreference (referring to the value captured in Group 1), space and Group 2 backreference (referring to the value captured in Group 2).


Viewing latest article 1
Browse Latest Browse All 3

Trending Articles