Regular Expressions

A regular expression, often shortened to regex or RegExp, describes a pattern in text. Instead of looking for one fixed value, you can find any order number, extract a price, or replace repeated spaces.

Tapicker uses JavaScript regular expressions. Start with a simple pattern and test it against text from your page before adding more rules.

Start with a Simple Pattern

Suppose the text is Order #123. The pattern \d+ matches 123:

  • \d matches a digit from 0 to 9.
  • + means one or more of the preceding item.

The same pattern finds 4567 in Order #4567. You do not need to know the number in advance.

By default, a regular expression can match just part of the input. For example, \d+ finds the digits in ABC123. To require the entire input to contain only digits, add start and end anchors: ^\d+$.

Use Regular Expressions in Tapicker

The pattern is the same, but how you enter it depends on the field.

Enter a Pattern in a Transformation

In Data Transformation, enter just the pattern in Pattern, without surrounding slashes or quotes:

\d+

Select flags with the control on the right. For example, select g to collect all number matches. The editor already displays the slashes around the pattern, and new regular-expression transformations start with g selected.

Choose the transformation for the result you need:

  • Test returns whether the text matches: true or false.
  • Match returns an Array of matches, or null if nothing matches.
  • Extract joins matches into a String, or returns an empty String if nothing matches.
  • Replace changes matching text, or removes it when Replacement is empty.

For an Array input, these transformations process each item individually. Test returns an Array of Boolean results, rather than one combined Boolean.

Use a Pattern in an Expression

Inside Template Syntax, write the pattern between slashes, followed by any flags:

{{ $vars.text | match(/\d+/g) }}

If text holds Items: 12 and 34, the result is ["12", "34"]. Use the corresponding Pipeline Functions to extract, replace, or test text:

{{ $vars.text | extract(/\d+/g, ' | ') }}
{{ $vars.text | replace(/\s+/g, ' ') }}
{{ $vars.text | test(/^ORD-\d+$/) }}

For extract, that sample text produces 12 | 34. The other examples replace consecutive whitespace with one space and check whether the entire text is an order ID such as ORD-123.

Match Text in a Selector

Tapicker's custom CSS selectors :contains() and :text() accept regular-expression patterns:

button:contains(/^Next$/i)

This matches a button whose combined text is exactly Next, ignoring capitalization. Text is normalized before matching: consecutive whitespace becomes one space, and surrounding whitespace is removed.

Quoted patterns such as button:contains("Next|Continue") also use regular-expression matching. See CSS Selectors for the difference between :contains() and :text().

Use URL Patterns for fields that ask you to match page, iframe, or request URLs. Those fields use URLPattern syntax rather than a plain regular expression.

Match Characters

Match Fixed Text

Ordinary letters and numbers match themselves. The pattern Anna finds Anna in Hello, Anna.

Matching is case-sensitive unless you enable i, so Anna does not match anna by default.

Use Character Shortcuts

Common shortcuts let you match a kind of character:

  • \d — an ASCII digit, equivalent to [0-9].
  • \D — any character that is not an ASCII digit.
  • \w — a basic word character: A–Z, a–z, 0–9, or _. It is not a general matcher for words in every language.
  • \W — a character outside that basic word set.
  • \s — whitespace, including spaces, tabs, and line breaks.
  • \S — a non-whitespace character.
  • . — any character except a line terminator, unless s is enabled.

For example, \s+ matches one or more consecutive whitespace characters. Replacing those matches with one space standardizes spacing.

Choose a Character Set

Square brackets match one character from a set:

  • [abc] — a, b, or c.
  • [a-z] — a lowercase English letter.
  • [A-Za-z] — an uppercase or lowercase English letter.
  • [0-9] — a digit.
  • [^0-9] — any character except a digit.

Inside a character set, an initial ^ means “not.” Outside a character set, ^ marks the beginning of the input.

Match Special Characters Literally

Characters such as ., *, +, ?, (, and ) have pattern meanings. Put a backslash before one when you want the character itself:

  • \. matches a literal dot.
  • \? matches a literal question mark.
  • \( and \) match literal parentheses.
  • \$ matches a dollar sign.

For example, Price \(USD\) matches the text Price (USD). Without escaping, the parentheses would create a group.

In a slash-delimited pattern inside an expression, escape a slash too: /https?:\/\// matches http:// or https://.

Control How Much Text Matches

Repeat a Character or Group

A quantifier controls how many times the preceding item repeats:

  • * — zero or more times.
  • + — one or more times.
  • ? — zero or one time.
  • {3} — exactly three times.
  • {2,} — at least twice.
  • {2,4} — between two and four times.

For example, colou?r matches both color and colour, while \d{5} matches a run of five digits. Use ^\d{5}$ when the whole input must be exactly five digits.

Match the Beginning, End, or a Whole Word

Use anchors and boundaries to limit where a pattern can match:

  • ^Save — text starting with Save.
  • Save$ — text ending with Save.
  • ^Save$ — the complete text Save.
  • \bcat\b — cat as a whole word, rather than part of catalog.

Word boundaries follow JavaScript's word-character rules; they are not a general way to split words in languages such as Chinese.

Choose Alternatives

Use | for alternatives. Group alternatives when they share surrounding conditions:

^(Save|Submit)$

This matches exactly Save or Submit. By comparison, ^Save|Submit$ means “starts with Save or ends with Submit,” because the anchors do not apply to both alternatives together.

Keep Matches Short with Lazy Quantifiers

Quantifiers such as * and + are greedy by default: they try to consume as much text as possible while allowing the rest of the pattern to match. Add ? after a quantifier to make it lazy, so it tries the shorter match first.

For input [red] [blue]:

  • \[.*\] matches [red] [blue] as one piece.
  • \[.*?\], with g, finds [red] and [blue] separately.

This is useful when extracting text between repeated delimiters.

Use Flags

Flags change how a pattern behaves. Select them in a transformation's flag control, or write them after the closing slash in an expression.

g — Find All Matches

Without g, Match and Extract use the first match, and Replace replaces only the first occurrence. With g, they process all matches.

For A1 B2, \d finds 1 first. With g, it finds both 1 and 2.

g does not turn Test into a count: Test still returns a Boolean for each input value. You normally do not need g for a text selector; it already tests each candidate element's text.

i — Ignore Letter Case

/next/i matches Next, NEXT, or next. Combine flags when needed, such as /save/gi to replace every occurrence regardless of capitalization.

m — Match Line Boundaries

With m, ^ and $ also match the beginning and end of individual lines. For example, /^Order:/m can find an Order: line inside a multiline description.

This does not make . match line breaks; use s for that.

s — Let Dot Match Line Breaks

With s, . can match line breaks as well as other characters. For example, /BEGIN.*?END/s can match a block spanning several lines.

u — Use Unicode-aware Matching

Use u for Unicode code-point handling and Unicode property patterns, such as /\p{Script=Han}+/u for a run of Han-script characters.

y — Match at the Current Position

Sticky matching starts exactly at the regular expression's current lastIndex, instead of searching ahead. This is an advanced flag; use ordinary matching for general extraction and text filtering unless you specifically need position-based matching.

Capture and Reuse Parts of a Match

Capture a Group

Parentheses capture a part of the matched text:

{{ 'Order #123' | match(/#(\d+)/) }}

The result is ["#123", "123"]: the full match followed by the captured digits.

With g, Match returns all full matches instead of captured groups:

{{ 'Order #123, Order #456' | match(/#(\d+)/g) }}

The result is ["#123", "#456"]. Extract uses the same match list and joins it, so captured groups also affect its result when g is off.

Use (?:...) when you need a group for alternatives or repetition without adding a captured value. For example, ^-?\d+(?:\.\d+)?$ checks a signed whole number or decimal without capturing the decimal part separately.

Reuse a Group in Replacement Text

In Replace, use $1, $2, and so on in the replacement to insert captured groups. $& inserts the entire match.

For example, to change 2026-01-02 to 02/01/2026, use:

  • Pattern: ^(\d{4})-(\d{2})-(\d{2})$
  • Replacement: $3/$2/$1

The equivalent expression is:

{{ $vars.dateText | replace(/^(\d{4})-(\d{2})-(\d{2})$/, '$3/$2/$1') }}

Inside a pattern, a backreference such as \1 matches the same text as the first captured group. It serves a different purpose from $1, which is used in replacement text.

Check Surrounding Text with Lookarounds

Lookarounds check nearby text without including it in the match:

  • \d+(?= USD) — digits followed by USD.
  • \b\d+\b(?! USD) — a whole number not followed by USD.
  • (?<=USD )\d+ — digits preceded by USD .
  • (?<![A-Za-z0-9])\d+ — digits not immediately preceded by a letter or digit.

For example, (?<=USD )\d+(?:\.\d+)? extracts 29.99 from USD 29.99, leaving USD out of the result. Use a capturing group and replacement when rearranging text is simpler than a lookaround.

Practical Examples

In the examples below, copy Pattern into a transformation's pattern field and choose the listed flags separately. In an expression, wrap the pattern in slashes and append its flags.

Extract Whole Numbers

  • Pattern: \d+
  • Flags: g

For Items: 12, Boxes: 3, Match returns ["12", "3"], and Extract with its default separator returns 12, 3.

The matches are text. Apply toNumber afterward if you need numeric values; Array inputs are converted item by item.

Check a Whole Number or Decimal

  • Pattern: ^-?\d+(?:\.\d+)?$
  • Flags: None

Matches

  • 42
  • 29.99
  • -3.5

Does not match

  • $29.99
  • 1,234.50
  • 12abc

This example accepts a decimal point and optional minus sign. It does not handle every locale's number format.

Remove a Currency Symbol Before Conversion

  • Pattern: [^\d.-]
  • Flags: g
  • Replacement: Empty

Using Replace, $1,234.50 becomes 1234.50, and -$29.99 becomes -29.99. Add toNumber afterward.

This is a cleanup rule for numbers written with a decimal point. It does not interpret a comma as a decimal separator or parentheses as a negative amount.

Normalize Whitespace

  • Pattern: \s+
  • Flags: g
  • Replacement: One space

Using Replace, Anna Smith becomes Anna Smith. Tabs and line breaks are also replaced with spaces. Add Trim afterward to remove leading or trailing whitespace.

Check an Order ID

  • Pattern: ^ORD-\d{4}$
  • Flags: None

Matches

  • ORD-0001
  • ORD-1234

Does not match

  • ORD-123
  • ord-1234
  • Order ORD-1234

Choose i as well if lowercase prefixes should be accepted.

Find Han-script Text

  • Pattern: \p{Script=Han}+
  • Flags: gu

For Product: 无线耳机, Color: 黑色, Match returns ["无线耳机", "黑色"]. This finds runs of Han-script characters; it does not include punctuation or every writing system used in Chinese-language text.

Check a Basic Email Format

  • Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$
  • Flags: None

Matches

  • support@tapicker.com
  • anna+orders@example.co.uk

Does not match

  • anna.example.com
  • anna@example
  • anna @example.com

This is a basic format check for ordinary addresses, not a complete email parser. A match does not prove that the mailbox exists.

Check a Phone Number Format

For a US-style number such as (562) 988-1688:

  • Pattern: ^\(\d{3}\)\s?\d{3}-?\d{4}$
  • Flags: None

It matches (562) 988-1688 and (562)9881688.

For an 11-digit mainland China mobile-number format:

  • Pattern: ^1[3-9]\d{9}$
  • Flags: None

It matches 13800138000. These patterns check the written format; adapt them if your source includes a country code or different separators.

Check a Postal Code Format

For a US ZIP code, with an optional four-digit extension:

  • Pattern: ^\d{5}(?:-\d{4})?$
  • Flags: None

It matches 90807 and 92064-3404.

For a six-digit mainland China postal-code format:

  • Pattern: ^[1-9]\d{5}$
  • Flags: None

It matches 100000 and 200000. A format match does not verify that a postal code is assigned.

Check a Date's Written Format

  • Pattern: ^\d{4}-\d{2}-\d{2}$
  • Flags: None

This matches text shaped like 2026-01-02. It also matches 2026-99-99, because it checks the shape rather than calendar validity.

Use the Date conversion and formatting options in Data Transformation when you need to work with dates as values.

  • Pattern: https?://[^\s<>"']+
  • Flags: g

For Visit https://example.com/help or http://example.org/about, Match returns those two URLs. This is a simple extraction pattern; punctuation attached to a URL, such as a final comma, may need to be cleaned afterward.

If you need a page's links, selecting <a> elements and extracting href is usually more direct. Use URL Patterns to match URL fields in Tapicker.

Extract Text Between Brackets

  • Pattern: (?<=\[)[^\]]+(?=\])
  • Flags: g

For [red] [blue], Match returns ["red", "blue"], without the brackets. This example assumes simple, non-nested bracket pairs.

FAQ

Why Does My Pattern Match Only Part of the Text?

Regular expressions search for a matching part unless you anchor them. Use ^ and $ when the whole input must match, and group alternatives, such as ^(Save|Submit)$.

Why Do I Get Extra Values in Match or Extract?

Without g, captured groups appear after the full match. Use a non-capturing group (?:...) if you only need grouping, or enable g when you need all full matches. See Capture a Group.

Why Does My Pattern Work in One Field but Not Another?

Check the input format. A transformation's Pattern field takes \d+, while an expression uses a literal such as /\d+/g. Text selectors also normalize whitespace before matching. URL Pattern fields use a different syntax altogether.

Use one backslash for a pattern entered directly in Tapicker's pattern field. If that pattern is stored inside a JSON String, JSON escaping requires two, such as "\\d+" to represent \d+.

Should I Use Regex to Parse JSON or HTML?

For JSON text, use toObject, toArray, or the decode('json') Pipeline Function, then read fields from the parsed data. A regex that searches for one property can fail when spacing, escaping, or nested values change.

For a webpage, use CSS Selectors and the appropriate extraction attribute. A regex is useful for cleaning extracted text, but it does not replace selecting HTML elements.

Further Reading