regexre2

Removing lowercase letter before an uppercase letter


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?


Solution

  • 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: