nd12y
nd12y

Reputation: 15

REGEX_EXTRACT for specific pattern inside brackets

Trying to use REGEX_EXTRACT in SQL to extract certain string patterns inside Brackets.

So I have tried this formula: REGEX_EXTRACT(column, r'\[(.*?)\]'), but problem is that there are multiple Brackets in the same cell, and this formula will only extract the first string pattern in the first bracket.

So, what I'm trying to figure out is how can I extract specific patterns within the Brackets? The pattern I'm looking for looks like this: [xx-XX] Where x can be any string in the alphabet.

Any tips or directions would be greatly appreciated

Upvotes: 0

Views: 534

Answers (1)

lapurita
lapurita

Reputation: 1175

This should work if you always have 2 lowercase letters followed by '-' and then followed by 2 uppercase letters:

\[([a-z]{2}-[A-Z]{2})\]

Upvotes: 1

Related Questions