TL;DR
- Find:
(?<!\$)\$(?!\$)(.*?)(?<!\$)\$(?!\$)
- Replace:
\\\($1\\\)
Instructions
- Open the Find and Replace panel in Visual Studio Code using
Ctrl + H
(Windows/Linux) orCmd + H
(Mac). - Make sure the regex mode is enabled by clicking on the
.*
button or pressingAlt + R
. - In the Find input field, enter the following regex pattern:
(?<!\$)\$(?!\$)(.*?)(?<!\$)\$(?!\$)
.- Here,
(?<!\$)\$
matches a single$
character that is not preceded by another$
. (?!\$)\$
matches a single$
character that is not followed by another$
.(.*?)
captures the content between the dollar signs.- The negative ‘lookarounds’,
(?<!\$)
and(?!\$)
, ensure that the$...$
strings are not preceded or followed by another dollar sign, effectively excluding$$...$$
strings.
- Here,
- In the Replace input field, enter:
\\\($1\\\)
.- Here,
\\\(
and\\\)
represent the literal characters\\(
and\\)
in the replacement string. $1
refers to the captured group from the find pattern, which contains the content between the dollar signs.
- Here,
- Ensure that the “Match Case” and “Match Whole Word” options are unchecked unless you want to perform a case-sensitive or whole-word search.
- Click on the Replace All button or use the Replace button to replace each occurrence individually.
Then, replacing $...$
strings with \(...\)
strings, excluding $$...$$
strings in Visual Studio Code using regular expressions becomes possible.
Attention
I replace using 3 backslashes, as Jekyll requires this to build the equations correctly.