2

I'm trying to use a regex search and replace to find and fix any unescaped quotation marks with escaped question marks. This is not in any particular language - just using regex to search and replace in Sublime Text 2.

I can find them just fine with this regex:

([a-zA-Z0-9!@#$%^&*()_+=-\?><:;\/])\"

Trying to replace is giving me some headaches. I thought this would work:

$0\\\"

but it's adding an extra quote in (or leaving the previous one there somehow).

e.g.,

e"

becomes

e"\"

instead of just

e\"

What the hey? I can't seem to find a combination in the replacement that will work!

2
  • What if the quote is already escaped? Is that a possibility? Commented May 20, 2014 at 23:58
  • It won't find those, because i don't have an escaped backslash in my search set. Commented May 29, 2014 at 21:51

1 Answer 1

2

In the replacement $0 will be a reference to the entire match, including the quote. It looks like you should be using $1 instead which will be the first capturing group, so just the character immediately before the quote. So your replacement string would be "$1\\\"".

Sign up to request clarification or add additional context in comments.

1 Comment

Bless you! I thought 0 just grabbed the first match. Thanks for straightening me out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.