Google Sheets Regexextract

468 Views Asked by At

If i have a string like abc_xyz, i can use =REGEXEXTRACT(B2, "(.*)_") to extract abc from it. But if i have a string like abc_xyz_qwe, the function will return abc_xyz.

So can you help me figure out how to get the formula to return only abc if there are multiple values separated by underscores in the string.

2

There are 2 best solutions below

0
Abhay On BEST ANSWER

Replaced =REGEXEXTRACT(B2, "(.*)_") with =REGEXEXTRACT(B2, "([^_]+)") and it started picking the part of the string before the first underscore.

Credit to: @CertainPerformance for the answer.

0
pnuts On

Without regex:

=left(B2,find("_",B2)-1)