Search code examples
regexgoogle-sheetsformulas

Google Sheets Regexextract


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.


Solution

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