6 views
# LOOKAROUND & GROUPS ## CAPTURE GROUP (abc) Each (cg) gets a backreference number starting from 1 ## BACKREFERENCE TO (CAPTURE GROUP) \1 \2 \3 For search & replace functions) ## NEGATIVE LOOKBEHIND (?<!ABC) Specifies a group that can not match before the main expression (if it matches, the result is discarded) ## POSITIVE LOOKBEHIND (?<=ABC) Matches a group before the main expression without including it in the result ## NEGATIVE LOOKAHEAD (?!ABC) Specifies a group that can not match after the main expression (if it matches, the result is discarded) ## POSITIVE LOOKAHEAD (?=ABC) Matches a group after the main expression without including it in the result # QUANTIFIERS & ALTERNATION ## OR ab|cd match ab or cd ## zero, maybe 1, 1+ a* match 0 or more of "a" a+ match 1 or more of "a" a? match 0 or 1 of "a" # QUANTIFIERS & ALTERNATION: exact, at least number a{5} match exactly 5 of "a" a{2,} match 2 or more of "a" # QUANTIFIERS & ALTERNATION: in between number a{1,3} match between 1 and 3 or "a" # QUANTIFIERS & ALTERNATION: as few as possible a+? match as few as possible a{2,}? match as few as possible # ESCAPED & SPECIAL CHARACTERS \. \+ \* \? reserved characters escape \^ \$ \\ \. reserved characters escape $ $ \{ \} reserved characters escape $$ $$ \| \/ reserved characters escape \t tab \n linefeed \r carriage return \v vertical tab \f form feed \0 null \000 octal escape \xFF hexadecimal escape \uFFFF unicode escape \u{FFFF} extended unicode escape \cI control character escape # ANCHORS ^abc$ start/end of string \b word boundary \B not-word boundary # CHARACTER CLASSES . any character except newline \w \d \s word, digit, whitespace \W \D \S not word, digit, whitespace [abc]any of a, b, or c [^abc] not a, b, or c [a-g] character between a & g # FLAGS: /searchString/[ igmuys ] i IGNORE CASE: Makes the whole expression case-insensitive. For example, /aBc/i would match AbC. g GLOBAL SEARCH: Retain the index of the last match, allowing subsequent searches to start from the end of the previous match. m MULTILINE: When the multiline flag is enabled, beginning and end anchors (^ and \$) will match the start and end of a line, instead of the start and end of the whole string. u UNICODE: When the unicode flag is enabled, you can use extended unicode escapes in the form \x{FFFFF}. y STICKY: The expression will only match from its last Index position and ignores the global (g) flag if set. s DOTALL: dot (.) will match any character, including newline.