Google-sheets – How to use the capturing group in a function

formulasgoogle sheetsregex

=REGEXREPLACE("string", "(ng)", UPPER("$1"))

The above returns "string", but should return "striNG".

I suspect that this is because UPPER is capitalizing the string "$1" rather than the string with the captured group substituted into it.

How can I make REGEXREPLACE output the expected result?

Best Answer

You could try splitting this into two parts returning the latter part as upper. Not sure how to nest the upper inside the regex in Gsheets.

=REGEXEXTRACT(A1,"stri") & upper(REGEXEXTRACT(A1, "(ng)"))

this returned for me:

string > striNG