0

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.

Abhay
  • 611
  • 6
  • 24

2 Answers2

2

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.

Abhay
  • 611
  • 6
  • 24
1

Without regex:

=left(B2,find("_",B2)-1)
pnuts
  • 56,678
  • 9
  • 81
  • 133