Contact

REGEX Function (LibreOffice Calc)

Text Advanced LibreOffice Calc LibreOffice 6.2

Use REGEX in LibreOffice Calc to extract matched text, replace patterns, remove characters, and work with regular expressions.

Verification status: Selected examples were executed in LibreOffice Calc 25.2.3.2. This does not establish that every formula and edge case was tested. How formula examples are checked

Availability and version history

  • Introduced: LibreOffice 6.2.
  • Availability: Supported in LibreOffice 26.8.1.1, verified against its function registry. This identifies a supported release, not a final working version.
  • Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
  • Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.

The LibreOffice Calc REGEX function can extract the text matched by a regular expression or replace matching text. The key difference is whether the optional replacement argument is omitted or supplied. An empty string ("") deletes a match; it does not extract it.

Native-tested visual example: Extract digits using a pattern

The first invoice description contains a three-digit reference after a letter and a hyphen.

Enter this formula in cell E5:

=REGEX(A5;"[0-9]+")

Expected result: 123. [0-9]+ matches one or more adjacent digits. Omitting the replacement parameter makes REGEX return the matched substring.

LibreOffice Calc 25.2 actual screenshot of the REGEX function with source cells, the formula in the formula bar, and result Extracted number: 123

Real screenshot captured from LibreOffice Calc 25.2.3.2. The selected E5 cell shows the calculated result and the formula bar displays the entered formula.

Download the editable REGEX example (.ods) — change the sample input cells and watch the calculation update.

Why it works: [0-9]+ matches one or more adjacent digits. Omitting the replacement parameter makes REGEX return the matched substring. Watch for: Supplying "" as the third argument removes the match; it does not extract it.

Verification: Example calculated in LibreOffice Calc 25.2.3.2. Screenshot is a genuine application capture, not a mockup.

Syntax

=REGEX(Text; Expression; [Replacement]; [Flags_or_Occurrence])
  • Text — source text or a cell reference.
  • Expression — the regular expression pattern (LibreOffice uses ICU regular expressions).
  • Replacement (optional) — omit this argument to extract matching text. Supply a string to replace a match, or "" to remove it.
  • Flags or occurrence (optional) — "g" replaces all matches; a number can select a particular occurrence.

The function was introduced in LibreOffice 6.2. In Calc locales that use semicolons to separate function arguments, use the semicolons shown here.

Extract matched text (omit the replacement)

Extract numbers from text

=REGEX("A123B"; "[0-9]+")

Result: 123

Extract the beginning of an email address

=REGEX("sam@example.com"; "^[^@]+")

Result: sam

Extract the domain after the @ sign

=REGEX("sam@example.com"; "(?<=@)[^@]+$")

Result: example.com

If there is no match and you have not provided a replacement argument, the result is #N/A.

Replace text

Replace the first sequence of digits

=REGEX("A123B"; "[0-9]+"; "X")

Result: AXB

Remove every digit

=REGEX("A12B3"; "[0-9]"; ""; "g")

Result: AB

The third argument is an empty string, so matching digits are removed. The fourth argument "g" tells Calc to replace all occurrences, not just the first.

Normalize repeated spaces

=REGEX("Hello   world"; " +"; " "; "g")

Result: Hello world

Case-insensitive matching

=REGEX("Hello WORLD"; "(?i)world"; "Earth")

Result: Hello Earth

The inline (?i) modifier makes the pattern case-insensitive; it is part of the regular expression, not an extra Calc function flag.

How to extract a specific occurrence

=REGEX("axbxcxd"; ".x"; ; 2)

Result: bx — the second match. Leave the replacement argument blank between the two semicolons when selecting an occurrence to extract.

Common mistakes and fixes

The result is missing text instead of extracting it

Using =REGEX("A123B"; "[0-9]+"; "") removes the first matching number and returns AB. For extraction, omit the third argument entirely: =REGEX("A123B"; "[0-9]+").

Only the first match is changed

Supply "g" as the fourth argument to replace all matches.

REGEX returns #N/A

An extraction pattern that finds no match produces #N/A. Check the pattern, cell value, and any leading or trailing whitespace.

The pattern is too broad

Use anchors (^ and $), literal escaping (such as \\. to match a period), or tighter character classes where appropriate.

Official documentation

See the LibreOffice Calc REGEX function documentation for the definitive argument definitions and examples.

Practical troubleshooting tutorials