Main Regex
# Regular Expressions
`?` Zero or one (optional character).
`*` Zero or more (optional characters).
`+` One or more (e.g. letter or word).
`.` Any character except new line `\n`.
`[]` Unordered Character Set – It'll always match only one position of the string.
`[A-Z]` Ranges – Matches one capital letter in the example.
`[^]` Negated Character Set. Example: `[^A-Z]` not uppercase letters.
`()` Group
`\d` Digit Character – Similar to `[0-9]`.
`\D` Not Digit Character.
`\w` Word Character – Similar to `[A-Za-z0-9_]`.
`\W` Not Word Character.
`\s` Whitespace Character – Similar to `[ \t\n\r\f]`.
`\S` Not Whitespace Character.
`{,}` Character Repetition [Range]
`|` Alternation (i.e Or)
`^` Beginning of string. It only represents location.
`$` End of string. It only represents location.
`^[].${}*()\+|?<>` Characters to escape with `\`
`\n` New line
`\t` Tab
`\r` Carriage return
`\v` Vertical tab
`\f` Form feed
`\b` Word boundary. Where one side is a word character and the other side is not a word character.
`\B` Not word boundary
# Assertions
`(?:regex)` Passive (i.e. non-capturing) group
`?=` Positive lookahead
`?!` Negative lookahead
`?<=` Positive lookbehind
`?<!` Negative lookbehind
`?>` Once-only Subexpression
`?()` Condition [if then]
`?()|` Condition [if then else]
`?#` Comment
# Flags
`i` Case-insensitive
`g` Global; keeps searching for the regex
`m` Multiline; considers the line break a part of the word
`s` Treat string as single line
`x` Allow comments and whitespace in pattern
`e` Evaluate replacement
`U` Ungreedy pattern
Usage: `/regex/igm`
# Captured Groups String Replacement
`()` Captured groups
`$n` nth non-passive group
`$$` Dollar sign escape
`$+` Last matched string
`$&` Entire matched string
`$'` After matched string
`$`` Before matched string
Rarely Used
`\` Escape following character
`\Q` Begin literal sequence
`\E` End literal sequence
`\A` Start of string
`\Z` End of string
`\<` Start of word
`\>` End of word
`\c` Control character
`\x` Hexadecimal digit
`\O` Octal digit
`\xxx` Octal character xxx
`\xhh` Hex character hh
https://cheatography.com/davechild/cheat-sheets/regular-expressions/
Processing Regex
/regex/i.test(string)
string.replace(/regex/g, substring)
const regexObj = /^regex$/ // Regex Literal
const regexObj = new RegExp("^word$"); // Regex Constructor