Last active
June 25, 2022 11:48
-
-
Save ruandre/b3b3c3403c2c544465d7a5ccf25999d4 to your computer and use it in GitHub Desktop.
RegEx Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// \s - any whitespace character (including \t, \n and a few others) | |
// \S - any non-whitespace character | |
// \w - any word character (uppercase and lowercase latin alphabet, numbers 0-9, and _) | |
// \W - any non-word character | |
// \b - word boundary (boundaries between \w and \W, matches in-between characters) | |
// \B - non-word boundary (inverse of \b) | |
// (?!) - negative lookahead | |
// (?=) - positive lookahead | |
// (?<=) - positive lookbehind | |
// (?<!) - negative lookbehind | |
vconst { log } = console | |
const s = 'See the parrot. And the goat. And the rooster.' | |
log(s.match(/\w+?(?=\.)/g)) | |
// Matches []: | |
// See the [parrot]. And the [goat]. And the [rooster]. | |
// (word before period/full-stop) | |
log(s.match(/the (?=goat)/g)) | |
// Matches []: | |
// See the parrot and [the ]goat and the rooster. | |
// ("the " only before "goat") | |
log(s.match(/the (?!goat)/g)) | |
// Matches []: | |
// See [the ]parrot and the goat and [the ]rooster. | |
// ("the " except before "goat") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment