I have a many files and in each file there is a line with the following (amongst other things). This line is not always in the same place, however, it starts from the beginning of the line. This line is also always different.
slug: bláh-téxt-hello-write-sométhing-ábout-arrow
I'd like to replace each occurrence of the special characters (á and é with their corresponding characters a and e). Each of those characters can be on this line many times also occur in the document in other places (which should not be replaced).
So the result is:
slug: blah-text-hello-write-something-about-arrow
I have this: find: ^slug: (.)((é)|(á))(.) replace: slug: $1(?2e)(?2a)$3
However, this seems to replace only one character at a time. How do I get it to run multiple times until there is no character to replace?
Thanks much for any insights.
CodePudding user response:
You can use
Find What: (?:\G(?!^)|^slug:\h*)[^\r\náé]*\K(?:(á)|é)
Or
Find What: (?:\G(?!^)|^slug:\h*).*?\K(?:(á)|é)
Replace With: (?1a:e)
Details:
(?:\G(?!^)|^slug:\h*)
- end of the previous match orslug:
and then zero or more horizontal whitespaces at the start of a line[^\r\náé]*
- zero or more chars other than CR, LF,á
andé
.*?
- will match zero or more chars other than line break chars, as few as possible\K
- the operator that discards all text matched so far(?:(á)|é)
- eitherá
(captured into Group 1) oré
.
In the replacement, (?1a:e)
, replaces the found match with a
if Group 1 matched, else, e
is used.
Extra information about the use of conditional replacement is available in my "Swapping multiple values using conditional replacement patterns in Notepad " YT video.
Extra information about the use of \G
operator can be found in another YT video of mine, "\G anchor use cases".