Reputation: 13534
I am trying to extract a substring from a string based on delimiter '.'(period). Can someone share your thoughts on how to do it using regexp_extract please. Thanks.
**
- Input:-
15.075
0.035
**
Output
075
035
Upvotes: 1
Views: 533
Reputation: 5934
From this answer, it appears that you can use parentheses to capture of the match, as you would in most regex systems. That is, match the whole ".[0-9]+", but only capture the numeric portion, by surrounding it with parentheses, like this:
select regexp_extract(input, r'\.([0-9]+)');
This says to match a period followed by one or more numbers, and to extract the numeric portion only. I think that the leading r
marks that string as a regular expression, but I can't find documentation on it.
Reference: https://cloud.google.com/bigquery/query-reference?hl=en#regularexpressionfunctions
Upvotes: 2
Reputation: 191749
It seems that you will want to use REGEXP_EXTRACT
REGEXP_EXTRACT(number, r'\.(\d+)')
Upvotes: 0