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
Extract order numbers
- Select JavaScript and Extraction mode.
- Enable
g. - Enter this pattern:
\bORD-([0-9]{4})\b
- Paste this input:
ORD-0042 pending
ORD-0187 sent
ORD-42 invalid
XORD-0001 invalid
- Enter
$1\nin 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 template | Exact output |
|---|---|
$1 | 00420187 |
$1, | 0042,0187, |
$1\n | 0042\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.
- Read the match count before copying the output.
- If the count is
0, treat the extraction as having no rows. Use an empty list in your downstream process. - To verify the setup, restore the positive order example above.
- Verify that the count is
2and the Extraction output contains0042and0187on separate lines.
Use the match count to distinguish a successful extraction from the zero-match display.
Regular substitution uses Order $1. Extraction uses $1\n and returns one identifier per line.