-
grep -P "<regex>" <path> # omit leading & trailing '/' from regex
-
sag "<regex>" <path> # omit leading & trailing '/' from regex
-
VS Code:
Ctrl+F > Alt+R
RegEx | Description |
---|---|
. | Any Character Except New Line |
\d | Digit (0-9) |
\D | Not a Digit (0-9) |
\w | Word Character (a-z, A-Z, 0-9, _) |
\W | Not a Word Character |
\s | Whitespace (space, tab, newline) |
\S | Not Whitespace (space, tab, newline) |
\b | Word Boundary |
\B | Not a Word Boundary |
^ | Beginning of a String |
$ | End of a String |
[] | Matches Characters in brackets |
[^ ] | Matches Characters NOT in brackets |
( ) | Either Or Group |
RegEx | Description |
---|---|
* | 0 or More |
+ | 1 or More |
? | 0 or One |
{3} | Exact Number |
{3,4} | Range of Numbers (Minimum, Maximum) |
ninja # 'ninja'
^ninja$ # exactly 'ninja' and nothing else
[ng]inja # 'ninja' or 'ginja'
ninja[1-9] # 'ninja1' to 'ninja9'
[^n]inja # every '_inja' except 'ninja'
[0-9]+ # multiple digits
a{3} # 3 'a's
[a-zA-Z]{5,8} # 5 to 8 characters
(cat|dog|bird) # 'cat' or 'dog' or 'bird'
M(r|s|rs)\.? # 'Mr/Mr./Ms/Ms./Mrs/Mrs.'
// these two are equivalent
const reg1 = /[a-z]/i
const reg2 = new RegExp(/[a-z]/, 'i')
reg1.test("b") // true
reg2.test("3") // false
const text = "http://www.google.com";
const regex = /https?://(www\.)?(\w+)(\.\w+)/
const [whole, www, domain, extension] = text.match(regex)