Quick Start
Tutorial
Search & Replace
Tools & Languages
Examples
Reference
Regex Tools
grep
PowerGREP
RegexBuddy
RegexMagic
General Applications
EditPad Lite
EditPad Pro
Google Docs
Google Sheets
LibreOffice
Notepad++
Languages & Libraries
Boost
C#
Delphi
F#
GNU (Linux)
Groovy
ICU (Unicode)
Java
JavaScript
.NET
PCRE (C/C++)
PCRE2 (C/C++)
Perl
PHP
POSIX
PowerShell
Python
Python.NET and IronPython
R
RE2
Ruby
std::regex
Tcl
TypeScript
VBScript
Visual Basic 6
Visual Basic (.NET)
wxWidgets
XML Schema
XQuery & XPath
Xojo
XRegExp
Databases
Google BigQuery
MySQL
Oracle
PostgreSQL
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
RegexBuddy—The best regex editor and tester for docs developers!

LibreOffice Regular Expressions

LibreOffice is a popular, cross-platform, open source office suite. Its regular expression support is based on the International Components for Unicode (ICU) library. The regular expressions tutorial and reference on this website do not mention LibreOffice specifically. Everything that is said about ICU’s regular expression and replacement text flavor also applies to LibreOffice.

LibreOffice does not provide a way to set matching modes outside the regular expression, except for case sensitivity in LibreOffice Writer. Regexes are case sensitive in LibreOffice Calc. The caret and dollar match at the start and end of each line. Particularly in LibreOffice Writer this is much more useful than only matching at the start and end of the document. But it is the default in LibreOffice Calc too. You can change any of the matching modes supported by ICU by placing a mode modifier at the start of your regex.

Find & Replace in LibreOffice Writer

In LibreOffice Writer, you can select Edit|Find & Replace in the menu or press Ctrl+H to search your document using a regular expression. You have to use the Find & Replace dialog even if you don’t want to make any replacements. The Find Bar at the bottom of the main window does not support regular expressions.

To enable regular expressions, tick the “regular expressions” checkbox in the Find & Replace dialog. Enter your regex into the Find box. You can make the regex case sensitive by ticking the “match case” checkbox. Otherwise it is case insensitive. The “whole words only” option is disabled for regular expressions. You can search for \bregex\b to match “regex” only when it occurs as a whole word.

Click the Find All button to highlight all regex matches. Click Find Next and/or Find Previous to select the next or previous regex match.

If you want to replace matches, enter the replacement text into the Replace box. You can use backreferences and all other features supported by the ICU replacement text syntax. After clicking Find Next or Find Previous you can click the Replace button to replace the selected match. Click the Replace All button if you want to replace all matches in the document.

REGEX Function in LibreOffice Calc

LibreOffice Calc has a single function that you can use to extract a regex match, replace a regex match, or replace all regex matches.

REGEX(Text, Expression) returns the first match that Expression finds in Text. You can use a literal string or a cell reference for each of the arguments. Text is the subject string and Expression is interpreted as an ICU regular expression. The function returns #N/A if there is no match. REGEX("abcd", "\w") returns "a".

REGEX(Text, Expression, , Occurrence) requires Occurrence to be a positive number. Note that there are 3 commas in the expression. Occurrence is the 4th argument. The 3rd argument is omitted. This form of REGEX() tries to find that many matches of Expression in Text as specified by Occurrence and returns match number Occurrence. The function returns #N/A if there are fewer matches than that (or no matches at all). If Occurrence is 0 then the function returns Text, regardless of whether there are any matches. An invalid regular expression is still an error when Occurrence is 0. A negative value for Occurrence is also an error. REGEX("abcd", "\w", , 3) returns "c".

REGEX(Text, Expression, Replacement) returns Text with only the first match that Expression finds in Text replaced by Replacement. You can use a literal string or a cell reference for each of the arguments. Replacement is interpreted as an ICU replacement string. The function returns Text unchanged if Expression does not find any matches. REGEX("abcd", "\w", "$0$0") returns "aabcd".

REGEX(Text, Expression, Replacement, Occurrence) returns Text with only the match indicated by Occurrence replaced by Replacement. The function returns Text unchanged if Expression finds fewer than Occurrence matches. REGEX("abcd", "\w", "$0$0", 3) returns "abccd".

REGEX(Text, Expression, Replacement, "g") returns Text with all matches that Expression finds in Text replaced by Replacement. The function returns Text unchanged if Expression does not find any matches. REGEX("abcd", "\w", "$0$0", "g") returns "aabbccdd".

Passing anything other than a positive number or the exact string "g" as the 4th argument is an error. Omitting the 3rd argument (Replacement) and passing "g" as the 4th argument has no effect. If you do you will extract the first regex match as happens when you omit both the 3rd and 4th arguments. The REGEX() function can only extract a single match.

| Quick Start | Tutorial | Search & Replace | Tools & Languages | Examples | Reference |

| grep | PowerGREP | RegexBuddy | RegexMagic |

| EditPad Lite | EditPad Pro | Google Docs | Google Sheets | LibreOffice | Notepad++ |

| Boost | C# | Delphi | F# | GNU (Linux) | Groovy | ICU (Unicode) | Java | JavaScript | .NET | PCRE (C/C++) | PCRE2 (C/C++) | Perl | PHP | POSIX | PowerShell | Python | Python.NET and IronPython | R | RE2 | Ruby | std::regex | Tcl | TypeScript | VBScript | Visual Basic 6 | Visual Basic (.NET) | wxWidgets | XML Schema | XQuery & XPath | Xojo | XRegExp |

| Google BigQuery | MySQL | Oracle | PostgreSQL |