Skip to main content

Using Regular Expressions

Overview

Regular expressions (regex) allow you to search for, extract, or replace specific patterns of text in Mailparser.

They can be used in:

  • Text filters
  • Table filters

Regex is useful when your data follows a consistent format, such as IDs, codes, or numbers.


How It Works

A regular expression defines a pattern that Mailparser looks for in your data.

If the pattern matches, the matching text is returned or modified depending on the filter being used.

Mailparser uses PCRE syntax.


Writing a Regex Pattern

Use Delimiters

All expressions must start and end with a delimiter, typically:

/pattern/

Other delimiters like # can also be used.


Examples

Match a 7 to 9 digit number

/\d{7,9}/

Match a code like AB-1234567

/[A-Z]{2}-\d{7}/

Common Regex Elements

Character Classes

  • \d → digits (0–9)
  • \w → letters, numbers, underscore
  • \s → whitespace
  • . → any character (except newline)

Meta Characters

  • ^ → start of text
  • $ → end of text
  • [] → character set
  • () → group
  • | → OR
  • \ → escape character

Quantifiers

  • * → 0 or more
  • + → 1 or more
  • ? → optional
  • {n} → exact number
  • {n,m} → range

These building blocks can be combined to create more precise patterns.


Tips

  • Start simple and refine your pattern
  • Use \d, \w, etc. instead of long character sets when possible
  • Test your regex before applying it

Summary

Regular expressions let you define patterns to find, extract, or modify data in Mailparser. They are powerful for handling structured data, but work best when your input follows a consistent format.

Was this article helpful?
0 out of 1 found this helpful

Still stuck?

Send us your inbox name and a sample email.

Submit a request