REGEXREPLACE Function in Gnumeric: Syntax, Examples and Troubleshooting

Text Intermediate Gnumeric

Replace regex matches, choose occurrences, and reuse captured 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: REGEXREPLACE substitutes substrings matching a regex. =REGEXREPLACE("ID: 12345","[0-9]+","*****") is expected to produce ID: *****. By default every match changes; an optional index targets a specific one.

Syntax and arguments

=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_insensitive])
Argument Required? Type and role
text Yes Source text or cell reference.
pattern Yes Regular expression identifying matches.
replacement Yes New text. Capturing groups can be inserted using $1, $2 or \1, \2 per GNOME C source.
occurrence No Integer; 0 (default) changes all matches, positive n selects the nth from start, negative -n selects the nth from the end.
case_insensitive No Boolean, default FALSE; pass TRUE for case-insensitive matching.

The inspected source returns unchanged input if no match, or if the requested nonzero occurrence doesn’t exist. Invalid regular expressions and invalid replacements can produce a #VALUE!-type error. These error paths are source-inspected, not native-tested.

Worked sheet: redact runs of digits

  1. Add headers Original to A1 and Masked to B1.
  2. Copy the A values below into A2:A5. They are fictional strings.
  3. Enter =REGEXREPLACE(A2,"[0-9]+","*****") in B2 and fill through B5.
Row A: Original Expected B result
2 ID: 12345 ID: *****
3 tel: 555-0134 tel: *****-*****
4 no digits no digits
5 order 22/88 order *****/*****

Why: [0-9]+ matches each consecutive run of ASCII digits. Since occurrence defaults to zero, each run is replaced by five asterisks. This is a text demonstration, not comprehensive privacy-preserving anonymization.

Advanced applications: one occurrence, captured parts, case folding

To replace only the second numeric run:

=REGEXREPLACE("A-123 B-456","[0-9]+","X",2)

Expected: A-123 B-X. Using -1 instead of 2 also replaces the last run and gives A-123 B-X. Using 9 leaves the original unchanged because that occurrence does not exist.

A capturing-group rearrangement:

=REGEXREPLACE("2026-10-11","^([0-9]{4})-([0-9]{2})-([0-9]{2})$","$2/$3/$1")

Expected: 10/11/2026 as text, not as a true date serial; this is not calendar-date validation. For case-insensitive replacement:

=REGEXREPLACE("CAT cat","cat","dog",0,TRUE)

Expected: dog dog.

Troubleshooting and limits

  • Too many matches replaced: The default occurrence=0 means all matches. Specify 1, 2 or -1 to narrow it.
  • Text unchanged unexpectedly: The pattern may not match, or the specified occurrence may be out of range. Verify the source text and case settings.
  • . matches too broadly: Use [.] for a literal period. Use ^/$ if the entire string must match.
  • Regex errors: Badly balanced ( or [ can fail compilation and return #VALUE!-type error in the inspected source. Complex backreferences should be tested with simple synthetic examples first.
  • Identifiers with leading zeros: Import ID fields as text so 0012 stays four characters.
  • Data privacy: Replacing number runs does not guarantee all identifiers are removed; check the remaining text and relevant policies.

Microsoft 365 Excel documents a similarly ordered five-argument REGEXREPLACE, including negative occurrence selection. Excel calls its last flag case_sensitivity; Gnumeric calls it case_insensitive. Engine differences and importer/exporter formula translations need native checking. For a known literal substring, use the simpler SUBSTITUTE instead of regex.

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

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.