Regex in Visual Studio Code
Basic recipes for regular expression in editor
VSCode primary support for regular expressions. Find and replace menu dialog can be opened with
Ctrl + Fkey combination.
find and replace menu options
It support plain text small, capital letters and regex.
We can search for new lines, carriage return, tabs, and spaces. Here for example, we would like to replace new line with comma (,) so that all the entries will be in csv.
The final result would look like this
conversion from newline to csv
With help of square brackets [ ], you can match for one (only one) of a set of characters.
Here the search goes for either of 1, 2, or 3 after immediately after # symbol.
- Important[:!,] searches for
- [AEIOUaeiou] searches for one of the letters in this set.
9 is a character, and 99 is a number with two characters 9 and 9.
For example for a long range of numbers or alphabets, it would be cumbersome. You can represent a range with a
—which acts as a metacharacter inside the square brackets
and outside it acts as a literal character.
[0-9]— matches number
- Small letter
Search for words without the listed characters in the set. Here,
^is the metacharacter for negation.
[^05]matches the numbers not divisible by 5.
[^a-zA-Z]matches other than alphabets.
check word with out a specific literal
] - ^ \are not literals inside the
[ ]. But,
. * ! , ; & $are all the literals. This means, -
aktxtonly. - we can escape
—inside the brackets, as
file[0\-]which also matches