Skip to content

Home

Common regular expressions

Exact string match

const regexp = /^abc$/;
// Where 'abc' is the exact string you want to match

Match empty string

const regexp = /^$/;

Match whitespace sequences

const regexp = /\s+/g;

Match line breaks

const regexp = /\r|\n|\r\n/gm;

Match non-word characters

const regexp = /[^\w\s]/gi;

Match alphanumeric, dashes and hyphens

const regexp = /^[a-zA-Z0-9-_]+$/;

Match letters and whitespaces

const regexp = /^[A-Za-z\s]+$/;

Pattern not included

const regexp = /^((?!(abc|bcd)).)*$/;
// Where 'abc' and 'bcd' are pattern you want to exclude

Text inside brackets

const regexp = /\(([^)]+)\)/g;

Validate GUID/UUID

const regexp = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;

Validate date format (DD/MM/YYYY)

const regexp = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;

Chunk string into n-size chunks

const regexp = /.{1,2}/g;
// Where '2' is the number of characters per chunk

More like this

Start typing a keyphrase to see matching snippets.