I was trying to replace all the small case letters that come before an uppercase letter on BigQuery.
For example:-
string = aDepartment of test, kHospital of test
After replacement
Department of test, Hospital of test
I have made the regex [a-z](?=[A-Z])
. This regex works fine on regex101. But when I use this regex on BigQuery, it shows Cannot parse regular expression: invalid perl operator: (?=
error.
I'm not able to understand what this error is about. Can anyone look into this regex so that it can work on BigQuery?
CodePudding user response:
Lookarounds are not supported in RE2 library.
You can use
regexp_replace(col, r'[a-z]([A-Z])', r'\1')
See the regex demo.
Details:
[a-z]
- an ASCII lowercase letter([A-Z])
- Group 1 (\1
): an ASCII uppercase letter.
CodePudding user response:
"Unfortunately, Google BigQuery is using the RE2 expression library, which is not currently supporting either positive or negative lookaheads"
I think you can ask regex101 to use a different engine so you're debugging something compatible with BigQuery, where you'll see ?=
is in error. If you don't need the lookahead, you can simply remove these two characters, just keep in mind you'll now be capturing that captial letter (so you'll need to add it back in your replace).