Code & computing / QUICK REFERENCE

Regular expressions

Character classes, anchors, repetition, groups and practical patterns—with the regex engine made explicit.

30 entries

Characters and classes

Literal sequence
/atlas/

Looks for that exact sequence. [2][1]

Any ordinary character
/./

Excludes line terminators unless dotAll is enabled. [2][1]

ASCII digit
/\d/

Matches 0 through 9 in JavaScript. [2][1]

Nondigit
/\D/

Complements the digit class. [2][1]

Word character
/\w/

Primarily ASCII letters, digits and underscore; not a universal alphabet class. [2][1]

Whitespace
/\s/

Includes more than an ordinary space. [2][1]

One of these characters
/[abc]/

Matches exactly one listed character. [2][1]

Not one of these
/[^abc]/

Negates the character class. [2][1]

ASCII lowercase range
/[a-z]/

Does not cover accented letters. [2][1]

Literal dot
/\./

Escapes the dot's special meaning. [2][1]

Repetition and anchors

Zero or more
/ab*/

Repeats b, not the whole ab sequence. [3][1]

One or more
/ab+/

Requires at least one b. [3][1]

Optional character
/colou?r/

Accepts color or colour. [3][1]

Exact count
/\d{4}/

Requires four consecutive digits, not necessarily the whole input. [3][1]

Bounded count
/\d{2,4}/

Matches between two and four digits. [3][1]

Lazy repetition
/a.*?b/

Chooses the shortest successful expansion. [3][1]

Start anchor
/^atlas/

Requires the match at input start without the m flag. [3][1]

End anchor
/atlas$/

JavaScript permits some line-ending behavior; validate full-input needs carefully. [3][1]

Word boundary
/\bcat\b/

Boundaries follow the engine's word-character rules. [3][1]

Whole ASCII digits
/^\d+$/

A simple nonnegative-integer shape, not a complete numeric parser. [3][1]

Groups and common operations

Alternation
/cat|dog/

Either alternative may match. [4][1]

Capture a group
/(ab)+/

Captures the repeated group. [4][1]

Group without capturing
/(?:ab)+/

Groups repetition without creating a capture slot. [4][1]

Named capture
/(?<year>\d{4})/

Reads the capture through groups.year after a successful match. [4][1]

Repeated word
/\b(\w+)\s+\1\b/

Backreference repeats the captured characters. [4][1]

Ignore case
/atlas/i

Case behavior depends on Unicode and engine rules. [4][1]

Find all matches
[...'a1 b2'.matchAll(/\d/g)]

matchAll requires a global regex argument. [4][1]

Test for a match
/\d/.test('item 2')

Returns a boolean. [4][1]

Replace matches
'a1 b2'.replace(/\d/g, '#')

Produces a# b#. [4][1]

Split on comma spacing
'a, b,c'.split(/,\s*/)

Produces three text fields for this simple input. [4][1]

Reserved placement, separate from reference controls. No ad network is active.

Updated JavaScript RegExp · common modern features

Sources

  1. Regular expressions guide ↗
  2. Character classes ↗
  3. Assertions ↗
  4. Groups and backreferences ↗