Regular Expressions

Note

Unless noted, all of the following is written with recent versions of JavaScript in mind. Different environments may support different regex features!

General

Match superscript and subscript numbers

\p{No}

Groups

(?:...) non-capturing group
(?<name>) named capturing group (the angle brackets are part of the syntax!)

Lookarounds

(?=...) positive lookahead
(?!...) negative lookahead
(?<=...) positive lookbehind
(?<!...) negative lookbehind

Lazy quantifiers

Add ? after any quantifier to make it lazy (match as few characters as possible).

For example, given the text: buffalo buffalo buffalo

/buffalo.+buffalo/ matches: buffalo buffalo buffalo

/buffalo.+?buffalo/ matches: buffalo buffalo buffalo

Substitutions

$& contents of match
$` contents before match
$' contents after match
$1 contents of capture group 1

Change case (VSCode)

Warning

These work in VSCode, but not in JavaScript!

\U start uppercasing
\L start lowercasing
\E stop changing case

ex. Title case Markdown headers:

Find:
(#\s*.)(.+)$

Replace:
\U$1\L$2

JavaScript