Using the Linter plug-in’s Custom Regex Replacement, I’m trying to add a ~ to any non-whitespace character followed by a an opening quote mark. Here’s my regex:
Replace: \S“
With: &~
The default “gm” is in the middle field. (What does “gm” mean?)
However, it’s replacing the found text with a normal “&” character, rather than the actual “found” text. What am I doing wrong?
gm in RegEx world stands for global and multiline … dixit RegEx101 as I’m no RegEx Expert …
RegEx101 is actually very useful when it comes to dealing with RegEx .
I mean, you could use it to test out the substitution you’re currently trying to put in place .
(I’m way too unconfident in my “RegEx skills” in this instant to actually make some suggestions , I’m sorry)
Can you also describe the objective and motivation behind what you’re trying to to do?
Because I think you probably want to keep the matched characters, no?
So you’d need to put the match in brackets – like so: (\S") –, then refer to that capture group with $1 (I think Linter uses that backreference method with the dollar sign).
I’m not adding a replacement here until we understand what you want.
Otherwise it’s easy to undo with CTRL+Z after you custom-lint a file.
Thanks! Your suggestion worked and it’s doing what I want now.
Basically, I’m using Linter to fix the way the Mac often puts quote marks in the wrong place when you dictate a quote.
In the past, I’ve used some regex variants where the ampersand character (&) in the “replace with” field keeps the matched characters. Maybe it was just a Mac thing.
Your approach using the backreference method is probably more universal.