Skip to content

Regex

Match, extract and replace text with a regular expression.

Runs a regular expression against a piece of text and does one of four things with it: takes the first match, takes every match, replaces the matches, or simply tests whether the text matches at all. Named capture groups are the reason this is usually a one-node job: a group like (?<amount>[\d.,]+) becomes a field called amount on the outgoing item, so you rarely need to drop to a Code node to reshape the result.

Use this node to pull a price, an ID, a date or any other fragment out of text — most often text you have just scraped from a page. Reach for it when you want to reshape a string, split one field into several, or branch a workflow on whether some text contains a pattern.

SettingNotes
OperationWhat to do with the pattern: Match (first match), Match all (every match), Replace, or Test. Defaults to Match.
PatternThe regular expression, without surrounding slashes. Named groups such as (?<price>[\d.]+) become fields on the outgoing item.
FlagsHow the pattern matches: Ignore case (i), All matches (g), Multiline anchors (m), Dot matches newlines (s), Unicode (u). Choose any combination.
TextThe text to match against. Accepts an expression such as {{ $json.description }}.
Source FieldName of the field holding the text, used only when Text is left empty (for example description).
ReplacementUsed by Replace: the text put in place of each match. Use $1 or $<name> to reference groups.
Maximum MatchesUsed by Match all: the most matches to collect before stopping. Defaults to 1000 and is capped internally; the output reports whether it stopped early.
Include Input FieldsKeep the incoming item’s fields alongside the result. On by default.
Put Result In FieldField that holds the match, the replaced text, or the test result. Defaults to match. Named capture groups are always added as fields of their own, regardless of this.

The shape depends on the operation:

  • Test — the item with your result field set to true or false.
  • Replace — the item with your result field set to the replaced text.
  • Match — the item with the result field set to the first match (or null), plus matched, a groups array of positional groups, and one field per named group. For example, (?<currency>[£$€])(?<amount>[\d.,]+) run against "Now $19.99" produces { currency: "$", amount: "19.99", match: "$19.99", matched: true }.
  • Match all — one item per match, each carrying match, matched, index, the groups array and the same named-group fields. If nothing matched, a single item comes through with the result field null and matched: false.

When Include Input Fields is on, the incoming item’s fields ride along with each result.

  • No credential or node dependency is required. The node runs entirely in the browser.

Scrape a product page, then connect it into Regex. Set Operation to Match, Source Field to description, and Pattern to (?<currency>[£$€])(?<amount>[\d.,]+). Each item now carries currency and amount fields you can feed straight into Edit Fields or a downstream request — no array indexing, no Code node.

  • A malformed pattern fails immediately with a clear message. Fix the pattern rather than the input.
  • Nothing matched is not an error. In Match the result field is null and matched is false; in Match all a single matched: false item comes through. Check your flags — case sensitivity and the g flag are the usual culprits.
  • Patterns are safe to run on large pages. Matching happens inside a worker that is terminated when a deadline passes, so a catastrophically backtracking pattern like (a+)+$ reports a timeout instead of freezing the tab. Caps on input length (~2M characters), pattern length (~2k characters) and match count (~10k) sit on top of that. If you hit a timeout, simplify the pattern rather than the text.
  • To reference a named group in a replacement, write $<name>; for a positional group, write $1.