Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escape metacharacters [ ] re2 in Google spreadsheets

I want use the function REGEXEXTRACT in a Google spreadsheets for retrive a string between brackets.

ex. in the cell A1 I have the text: qwertyui (asdfghjk)
I need the text asdfghjk.

The function =REGEXEXTRACT(A1, "\(([A-Za-z /]+)\)") works finely but when I have a text like qwertyui ([asdfghjk]) the function doesn't return nothing because the regular expression that I use does not have the square brackets.

I tried to add the characters "[" and "]" but they are metacharacters. I used the notation \[ (and \]) but don't works.
Google spreadsheets use regular expression re2. Is the notation correct?

Anyone know how to escape from metacharacters (or where I am wrong)?

like image 654
cicciocappuccio Avatar asked Nov 08 '25 16:11

cicciocappuccio


1 Answers

Use "\(([A-Za-z\[\] /]+)\)" or ("smart" placement) "\(([][A-Za-z /]+)\)".

enter image description here

or

enter image description here

However, since you are just extracting any text inside parentheses, you can make use of a negated character class [^()] that matches any character but a ( and ).

=REGEXEXTRACT(A1, "\(([^()]+)\)")

enter image description here

like image 186
Wiktor Stribiżew Avatar answered Nov 10 '25 09:11

Wiktor Stribiżew