LibreOffice Calc: return regex capturing parentheses

Viewed 85

I want to get the site name from a URL in LibreOffice Calc. Currently, I have this formula

=REGEX("https://stackoverflow.com/questions/..." , "://(.+)/")

It outputs ://stackoverflow.com/. I want it to output stackoverflow.com but I don't understand how to make it return the capturing parentheses content.

1 Answers

Unlike the Google-Sheets RE2 regex functions, LibreCalc provides ICU based functionality. Therefor you could try:

enter image description here

Formula in A1:

=REGEX("https://stackoverflow.com/questions/...";"(?<=://)[^/]+")
  • (?<=://) - A positive lookbehind to assert position is preceded by literally '://'.
  • [^/]+ - A negated character class to find 1+ characters other than forward slash.

A more convulated way would be to replace the input with a 1st capture group:

=REGEX("https://stackoverflow.com/questions/...";"^.*://([^/]+).*$";"$1")
Related