In a field, I'd like to extract text before first underscore if just one underscore. and if there are two underscores, extract text between the two. I can't seem to get a regex formula to work.
Example:
aywkhqeq_abcde_weyfb
abc_weyw
Is there a regex that can match abcde in the first one and abc in the second?
Solved! Go to Solution.
Hi @gwiz ,
Yes, there is a formula.
Use the parse method and the following expression: .*?([^_]+)_[^_]+$
Let me know if that works for you.
Best,
Fernando Vizcaino
@gwiz ,
I simplified the conditions and constructed this formula:
IF REGEX_COUNTMATCHES([Field1],"_") = 1 THEN
REGEX_Replace([Field1], "(.*?)_.*", '$1')
ELSE
REGEX_Replace([Field1], ".*?_(.*)_.*", '$1')
ENDIF
Cheers,
Mark