VS Code REGEX
Don't Include Comments
^(?![ \t]*//).*<your search term here>
Remove Line Breaks Replace \n\n\n with \n
Regular Expressions
- regexone.com
- https://regexr.com/
- RegExp Cheatsheet
:.*\{
.*\{
JS
JS Regex is useful for:
- search text a string
- replace substrings in a string
- extract information from a string
How does a Regular Expression look like
In JavaScript, a regular expression is an object, which can be defined in two ways.
The first is by instantiating a new RegExp object using the constructor:
const re1 = new RegExp('hey')
The second is using the regular expression literal form:
const re1 = /hey/
You know that JavaScript has object literals and array literals? It also has regex literals.
Meta Characters
\dmatches any digit, equivalent to[0-9]\Dmatches any character that’s not a digit, equivalent to[^0-9]\wmatches any alphanumeric character (plus underscore), equivalent to[A-Za-z_0-9]\Wmatches any non-alphanumeric character, anything except[^A-Za-z_0-9]\smatches any whitespace character: spaces, tabs, newlines and Unicode spaces\\Smatches any character that’s not a whitespace\0matches null\nmatches a newline character\tmatches a tab character\uXXXXmatches a unicode character with code XXXX (requires theuflag).matches any character that is not a newline char (e.g.\n) (unless you use thesflag, explained later on)[^]matches any character, including newline characters. It’s useful on multiline strings
Escaping
These characters are special:
\/[ ]( ){ }?+*|.^\$
They are special because they are control characters that have a meaning in the regular expression pattern, so if you want to use them inside the pattern as matching characters, you need to escape them, by prepending a backslash:
/^\\\$/
/^\^\$/ // /^\^\$/.test('^') ✅
/^\\$\$/ // /^\\$\$/.test('\$') ✅