Skip to main content

Extract values from matches

When the pattern matches, Extraction builds output from those matches and discards unmatched input. The extraction template controls both the values and their separators.

Free
Included
Pro
Included
Self-hosted
Included
Compare plans

Extract order numbers​

  1. Select JavaScript and Extraction mode.
  2. Enable g.
  3. Enter this pattern:
\bORD-([0-9]{4})\b
  1. Paste this input:
ORD-0042 pending
ORD-0187 sent
ORD-42 invalid
XORD-0001 invalid
  1. Enter $1\n in the extraction template.

The output contains each captured number followed by a newline:

0042
0187

There is also a newline after 0187. In JavaScript extraction output, \n inserts a line break.

Choose a separator​

The editor concatenates the template output for each match. It does not add a separator automatically.

Extraction templateExact output
$100420187
$1,0042,0187,
$1\n0042\n0187\n

The comma example includes a final comma. For a downstream format that forbids it, remove that final separator after extraction.

Compare the operations​

For the same pattern and replacement Order $1, ordinary substitution preserves the status words and line break. Extraction returns Order 0042Order 0187 because it keeps only the template output.

If the output contains only one value, verify that g is active. If a capture reference appears literally, verify its syntax for the selected engine.

Handle zero matches​

The current interface can show the original input in the Extraction output when the pattern finds no matches. Do not treat that text as an extracted result.

For example, replace the input above with no orders here. The match count is 0, but the output still shows no orders here.

  1. Read the match count before copying the output.
  2. If the count is 0, treat the extraction as having no rows. Use an empty list in your downstream process.
  3. To verify the setup, restore the positive order example above.
  4. Verify that the count is 2 and the Extraction output contains 0042 and 0187 on separate lines.

Use the match count to distinguish a successful extraction from the zero-match display.

Switch from Substitution to Extraction, enter a template, then inspect the zero-match display.

Regular substitution uses Order $1. Extraction uses $1\n and returns one identifier per line.