RegEx

RegEx Visualizers

Generators

About

  • RegEx => Regular Expressions.

Specials
  • If you want them literally, prefix with \ .

.^$*+?{}[]\|()
Sets
  • []

    • Match a character within a set.

    • [abc]  → one of a, b, or c

    • [a-z]  → any lowercase letter

  • [^...]

    • [^\d]  → anything except digits

    • Match a character not  within a set.

    • [^a-z]

      • any character not a lowercase letter

      • Matches, for example: A , 1 , # .

    • [^0-9]

      • Any non-digit

      • Matches, for example: a , ! .

    • [^\]]

      • Any char except ] .

    • [^\]|]

      • Any char except ]  or | .

Quantifiers
  • *

    • 0 or more

  • +

    • 1 or more

  • ?

    • 0 or 1

  • {n}

    • exactly n

  • {n,}

    • n or more

  • {n,m}

    • between n and m

Group
  • Capture :

    • ( )

      • capture a portion of the match.

      (hot)(dog)
      
      • Group 1 = hot ; Group 2 = dog .

  • Non-capturing :

    • no memory.

    • (?:...)

Alternation
  • |

    • cat|dog

    • cat or dog.

Shorthands
  • \d

    • Digits.

    • [0-9]

    • \D  negated

  • \s

    • Whitespaces.

    • [\t\n\f\r ]

    • \S  negated

  • \w

    • Word chars.

    • [0-9A-Z_a-z]

    • \W  negated.

  • .

    • Any char, except newline.

  • .*

    • Any char.

  • .*?

    • Any char, non-greedy. Shortest match.

Anchors
  • ^

    • Start of string.

  • $

    • End of string.

  • \b

    • Word boundary.

Lookaround Syntax
  • (?=...)

    • lookahead (must be followed by)

  • (?!...)

    • negative lookahead (must not be followed by)

  • (?<=...)

    • lookbehind (must be preceded by)

  • (?<!...)

    • negative lookbehind

    • (?<!!)\[\[

      • Ensures there is no !  immediately before the [[  pattern.