Regexp extract to match number of 8 digits after a known string in BigQuery

I need to extract 8 digits after a known string:

\n\n
| MyString                     | Extract: | \n| ---------------------------- | -------- | \n| mypasswordis 12345678        | 12345678 | \n| # mypasswordis 12345678      | 12345678 | \n| foobar mypasswordis 12345678 | 12345678 |\n
\n\n

Solution:

Use

\n\n
SELECT REGEXP_EXTRACT(MyString, r"mypasswordis\s*([0-9]{8})"))\n
\n\n

Or just

\n\n
SELECT REGEXP_EXTRACT(MyString, r"mypasswordis\s*([0-9]+)"))

mCollins

posted on

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds