Home > Software engineering >  BigQuery Regex to extract string between two substrings
BigQuery Regex to extract string between two substrings

Time:12-10

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.

CodePudding user response:

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

if applied to sample data in your question - output is

enter image description here

  • Related