dingdongdell
dingdongdell

Reputation: 59

BigQuery Regex to extract string between two substrings

From this example string:

{&q;somerandomtext&q;:{&q;Product&q;:{&q;TileID&q;:0,&q;Stockcode&q;:1234,&q;variant&q;:&q;genomics&q;,&q;available&q;:0"}

I'm trying to extract the Stockcode only.

REGEXP_REPLACE(col, r".*,&q;Stockcode&q;:/([^/$]*)\,&q;.*", r"\1")

So the result should be

1234

however my Regex still returns the entire contents.

Upvotes: 1

Views: 1798

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173210

use regexp_extract(col, r"&q;Stockcode&q;:([^/$]*?),&q;.*")

if applied to sample data in your question - output is

enter image description here

Upvotes: 3

Related Questions