Writing Regex formulas in LibreCalc

This regex finds 4 digit years: \d{4}

This regex replaces the found text (adding parentheses around the year): ($0)

How do I write this as a formula in LibreCalc?

Thank You

Most likely, using REGEX function.


They are REGEX but LibreCalc uses a very different syntax. I need help converting/translating standard Regex to LibreCalc regex.

No it doesn’t (and the documentation that I mentioned contains a reference to the full syntax, which is what ICU engine uses). Your regex snippets work fine. Instead of providing as little info as possible, consider providing as much info as possible, like “in this file: [inserted sample ODS here], the formula in A1 is [=this], and it references [this data] from B1. I expect A1 to be X, but I see Y…”

By the way: what is “standard Regex”? :wink: POSIX? ECMAScript? Perl? … ?

There are lots of RegEx “flavors”, but there isn’t a special syntax/flavor used in LibreOffice.
Most of commonly used RegEx constructs work anyway, the “flavor” is ICU: https://unicode-org.github.io/icu/userguide/strings/regexp.html. This is independent of whether you use the constructs with F&R or with the REGEX() function. Concerning the parameters for REGEX() read the help (linked to above by @mikekaganski).

The best tutorial (from my point of view - and also pointing to differences between flavors) is Regular Expression Tutorial - Learn How to Use Regular Expressions.

Concerning the REGEX() function there is one case probably not sufficiently emphasized by the help: The omission of the third (replacement) parameter doesn’t default to anything, but is positive information in itself: “Return the nth single finding where n is given by the fourth parameter”.