REGEXEXTRACT Function in Gnumeric: Syntax, Examples and Troubleshooting
Extract matching text and optionally return all matches or capturing groups. Learn exact arguments, reproducible examples and common errors.
Verification status: Official documentation referenced; example outcomes independently reasoned or arithmetically checked where stated. Not executed in Gnumeric. How formula examples are checked
Quick answer: REGEXEXTRACT extracts text matching a regular expression. =REGEXEXTRACT("PO-204","[0-9]+") is expected to return the text "204". Mode 1 returns all matched substrings in a vertical array; mode 2 returns capturing groups from the first match in a horizontal array.
Syntax and arguments
=REGEXEXTRACT(text, pattern, [return_mode], [case_insensitive])
| Argument | Required? | Type and role |
|---|---|---|
text |
Yes | Source text or cell reference. |
pattern |
Yes | Regex describing the part(s) to extract. |
return_mode |
No | Integer 0 (default): first whole match; 1: all whole matches vertically; 2: captured groups from the first match horizontally. |
case_insensitive |
No | Boolean; omitted is FALSE (case-sensitive), TRUE enables case-insensitive matching. |
For mode 2, include (...) capturing groups in the pattern. A matched numeric-looking substring remains text; apply VALUE if a numerical calculation is needed, after checking that the capture is a valid numeric format. In the inspected Gnumeric C implementation, no match returns a #N/A-type error; malformed regex returns a #VALUE!-type error; unsupported return modes ultimately give #N/A.
Reproducible worksheet example: get order numbers from labels
- Type
Labelin A1 andFirst numeric substringin B1. - Enter the values shown below in A2:A5.
- Enter
=REGEXEXTRACT(A2,"[0-9]+")into B2, then fill B2:B5.
| Row | A: Label | B: formula | Expected B value |
|---|---|---|---|
| 2 | PO-204 |
=REGEXEXTRACT(A2,"[0-9]+") |
text "204" |
| 3 | INV-007 |
=REGEXEXTRACT(A3,"[0-9]+") |
text "007" |
| 4 | Batch 9 / 12 |
=REGEXEXTRACT(A4,"[0-9]+") |
text "9" |
| 5 | Ref: ABC |
=REGEXEXTRACT(A5,"[0-9]+") |
#N/A-type error (expected from inspected error path) |
Why: [0-9]+ selects the earliest run of one or more ASCII digits, without converting them to numeric values. It therefore preserves leading zeros in row 3.
Advanced example: extract all matches versus capture groups
For an input string containing three alphanumeric labels:
=REGEXEXTRACT("A12 B34 C56","[A-Z][0-9]+",1)
Expected output: a one-column / three-row array, in order: A12, B34, C56. This is not a comma-separated text result. Verify how Gnumeric displays or places arrays in the installed release before enabling related screenshots or downloadable files; no native layout was tested here.
For an order code and two capturing groups:
=REGEXEXTRACT("PO-204","([A-Z]+)-([0-9]+)",2)
Expected output: a one-row / two-column array: PO then 204. Return mode 2 returns the group captures, not the full PO-204 match. To extract a decimal price from PO-204 $12.50, avoid a vague [0-9]+ pattern (which would select 204); instead use =REGEXEXTRACT("PO-204 $12.50","[0-9]+[.][0-9]{2}"), expected text "12.50".
Errors, limits, and practical checks
- Wrong substring: Without anchors or a more specific expression, the first match may be an ID rather than a later quantity or price.
- No match: The inspected implementation yields
#N/A-type failure; trap it withIFERRORif a blank or explanatory label is more useful, but avoid silently discarding unexpected source data. - Bad regex: Unbalanced parentheses or brackets can produce a
#VALUE!-type error in the inspected source. - Missing captures in mode 2: Put parentheses around each desired group. Without any capturing groups, the inspected implementation has no array value to return.
- Array output: Modes
1and2yield array values. The shape is documented in the source; actual spill/selection behaviour was not native-tested, so test in a disposable sheet before relying on neighboring cells. - Number conversions: ` “,”" or currency signs in captured text may prevent numeric conversion. Store IDs with leading zeros as text.
Compatibility and related tutorials
Excel Microsoft 365 also documents modes 0/1/2, but its fourth flag is called case_sensitivity. Excel specifies PCRE2; the Gnumeric implementation uses GLib GRegex. Test patterns with special features and array results in the relevant target software, rather than assuming every workbook will behave identically.
Availability and formula conventions
These examples target Gnumeric 1.12.62, whose official release announcement lists this function as newly introduced. Its registered name and argument information were checked against the GNOME source-code function definitions and string-function registry (GitHub’s GNOME mirror, pinned to commit 5d556a736fa3). The project’s release-specific source archive was enumerated in the pre-existing independent catalogue audit, but its bytes were not downloaded again in this batch. The public Gnumeric function index lags the audited release registry; absence from that list does not prove absence from 1.12.62. This guide does not promise availability in earlier versions or every downstream installation with different plugins.
Formulas use an English-language, comma-separated argument style with decimal dots where necessary. Regional settings can change the displayed argument separator and translated user interface; if pasting fails, insert the function through Gnumeric’s own function editor. Regex patterns are strings, so put double quotes around literal patterns in a formula; cell references such as A2 do not take quotes. A regex searches for a match within a string unless you explicitly anchor it with ^ and $. The implementation calls GLib GRegex; pattern portability with other spreadsheet regex engines is not guaranteed.
Official reference and verification
- Gnumeric — function documentation
- GNOME source-code function definitions
- string-function registry
- Gnumeric function index
Verification status: Official documentation checked; example outcomes were independently reasoned or arithmetically checked where applicable. Not executed in Gnumeric.
- No genuine Gnumeric screenshots are included; this guide does not use mock application images.