Home/Glossary/Regular Expressions (Regex)

Regular Expressions (Regex)

Pattern-matching syntax used to search, validate, and manipulate text based on rules.

DevelopmentAlso called: "regex", "regexp", "pattern matching"

Regular expressions define search patterns using special characters and quantifiers.

Common patterns

  • ^ and $: Match start and end of string.
  • . : Any character except newline.
  • \d, \w, \s: Digits, word characters, whitespace.
  • +, *, ?: One or more, zero or more, zero or one.
  • [abc], [^abc]: Character sets and negation.

Use cases

  • Validate email addresses, phone numbers, URLs.
  • Extract data from logs and text files.
  • Find and replace patterns in code.
  • Input sanitization and data parsing.

Security warnings

  • Catastrophic backtracking (ReDoS) can cause denial of service.
  • Always test regex performance with adversarial inputs.