3

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)?

4

2 回答 2

2

使用"\(([A-Za-z\[\] /]+)\)" 或(“智能”放置)"\(([][A-Za-z /]+)\)"

在此处输入图像描述

或者

在此处输入图像描述

但是,由于您只是提取括号内的任何文本,因此您可以使用与除 a和之外的任何字符匹配的否定字符类[^()]()

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

在此处输入图像描述

于 2016-01-05T22:51:44.627 回答
0

您实际上可以将其简化为:

=REGEXEXTRACT(A1,"\((.*\))")
于 2016-02-28T05:46:29.287 回答