Replace a Regex look ahead for Google Big Query
Question:
I have some data for which i want to select the LAST VALUE BEFORE THE DELIMITER
Example- A -> B -> C -> D
In this case, i want to select "C" so i used a positive look ahead but BQ doesnt allow look aheads/behinds
Here is the Regex, (?=[^n>]-[^n-]$)[^n-]*
Can someone help me replace the look ahead?
Answers:
You don’t need any lookarounds and can use a simple regex like following and extract your needed contents from group1.
^.*->(.*)->.*$
Explanation:
^
– Matches start of text
.*->
– Matches any text greedily and second last delimiter
(.*)
-> Captures the text between second last and last delimiter in group1
->
-> Matches last delimiter
.*$
-> Matches some text optionally after last delimiter and end of line
I have some data for which i want to select the LAST VALUE BEFORE THE DELIMITER
Example- A -> B -> C -> D
In this case, i want to select "C" so i used a positive look ahead but BQ doesnt allow look aheads/behinds
Here is the Regex, (?=[^n>]-[^n-]$)[^n-]*
Can someone help me replace the look ahead?
You don’t need any lookarounds and can use a simple regex like following and extract your needed contents from group1.
^.*->(.*)->.*$
Explanation:
^
– Matches start of text.*->
– Matches any text greedily and second last delimiter(.*)
-> Captures the text between second last and last delimiter in group1->
-> Matches last delimiter.*$
-> Matches some text optionally after last delimiter and end of line