Using OpenOffice sCalc - How to use IF function with REGEX capture and if true print capture to cell

StackOverflow https://stackoverflow.com/questions/22506970

  •  17-06-2023
  •  | 
  •  

Question

I have a worksheet (OpenOffice sCalc) with many rows of data, MOST of them have a year enclosed in ()

One of the cell's has this content: Mary had a little lamb, Sarah Josepha Hale (1830)

I would like to capture the year and save it in the cell to the right.

This stmt will tell me if a year is present:

=IF(COUNTIF(L115; ".*[(][0-9]{4,4}[)].*");"hooray"; "boo")

When I try to replace "Hooray" with $1 in this stmt I get an error:

=IF(COUNTIF(L115; ".*([(][0-9]{4,4}[)]).*");$1; "boo")

I get this: #REF!

What is the correct syntax? Thank you in advance!

Was it helpful?

Solution

Regex capturing is possible in Search/replace (must be enabled under "More Options"), but I don't know if you can use capturing in formulae.

An alternative way:

=VALUE(MID(L115;FIND("(";L115)+1;4))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top