'How to extract data between square bracket [ ], but there are two square brackets [ ]
#Today: I have a pair [sneakers] in [blue]
As per the data above, how should i extract the keywords blue in the 2nd square bracket ? I try to use formula below, but it only extracts the words in the first [ ] sneakers instead of blue.
=REGEXEXTRACT(B2,"\[(.*?)\]")
Solution 1:[1]
Formula:
=INDEX(SPLIT(REGEXEXTRACT(REGEXREPLACE(B2, "\][^\[\]]*\[", ","), "\[(.*)\]"), ","),,2)
Formula above replaces instances of ]<any non square bracket>[ to , then use the result and fetch the string inside the square bracket [sneakers,blue,test] then split using , and get the nth column.
To see how the formula works, separate it into 4 parts (per function).
Change last parameter to what order you want to get.
UPDATE:
=IFNA(REGEXEXTRACT(B2, "\][^\[\]]*\[[^""].*""([^""].*)""[^\""].*"),
INDEX(SPLIT(REGEXEXTRACT(REGEXREPLACE(B2, "\][^\[\]]*\[", ","), "\[(.*)\]"), ","),,2))
Output:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


