-2

If I have a string such as:

[text1]Blablablabla[text2]blalal

How do I extract only what is inside first []?

I use this formula to extract content between []

REGEXEXTRACT(B52, "\[(.+)\]")

With above formula I would get: text1][text2.

Not sure how to limit it only for the first pair of [] though, where I would get only text1

player0
  • 124,011
  • 12
  • 67
  • 124
NadanSHA
  • 77
  • 6

2 Answers2

0

My guess is that this expression might simply work:

REGEXEXTRACT(B52, "^\[(.+?)\]")

or if lookarounks are supported,

REGEXEXTRACT(B52, "(?<=^\[)[^\]]*")

Demo 2


If you wish to explore/simplify/modify the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.


Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    Thank you very much! I just modified it a little bit in case first brackets are not at the beginning of the string (i.e. removed ^). – NadanSHA Sep 01 '19 at 22:47
0
=REGEXEXTRACT(SPLIT(A1, "]"), "\[(.+)")

0

=REGEXEXTRACT(A1, "\[(.+?)\]")

0

player0
  • 124,011
  • 12
  • 67
  • 124