# 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.

\d{4}
(\$0)

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â€ť? 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â€ť.

2 Likes
``````=REGEX(A1;"\d{4}";"(\$0)";"g")
``````