Conditional Replace Char
-
Hey guys.
I need technical help.
Here’s the thing: a specific character appears multiple times in the text.
I need to change (replace) it for another character, but only if it doesn’t have a (blank) space before and after, but rather with one other different…
Text example (original):Verbo1 - Diga-lhe.
Verbo1 - Verbo2 - Diga-lhe. Fale-nos.
Verbo1 - Verbo2 - Verbo3 - Verbo4 - Diga-lhe. Fale-nos. Veja-as. Mande-nos.In the 3-line text above, if I change (replace) “-” (hyphen) to “,” (comma), will swap all hyphens. But I want you to change(replace/swap) only the ones that are NOT in between space, so the new text (end result) is:
Verbo1 - Diga,lhe.
Verbo1 - Verbo2 - Diga,lhe. Fale,nos.
Verbo1 - Verbo2 - Verbo3 - Verbo4 - Diga,lhe. Fale,nos. Veja,as. Mande,nos.Notice, replaced only the hyphens that are in the middle of the words.
The ones that are “loose” or “in the void”, have not been modified.
That’s what I need.How do I do this?
Thanks
-
Find what:
\b-\b
Replace with:,
and select Regular expression at the bottom, then click Replace All.
Explanation:
\b
represents a “word boundary” — a place where a word character (a letter, a digit or an underscore) and a non-word character are adjacent. The hyphens you want to replace have word boundaries on both sides since the hyphen is not a word character, and the characters on either side are. The hyphens you don’t want to replace do not have word boundaries on either side, since neither the hyphen nor the space is a word character. -
@Coises , thanks.
Worked perfectly.
I did a test, using a letter and not the hyphen.
In this case, it was exactly the opposite, replacing the isolated letter, not the letter in the middle of the word. So here we have a new trick: finding loose letters in the text.