Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract string before "_" or "." characters

I want to extract string before "_" or "." characters. e.g.. My C column can have following values and expected output in E:

C                            E
115415.csv                115415
12345_BOI_CEO.csv         12345

I have a formula for "_" i.e.

IFERROR(LEFT(C10, FIND("_", C10)-1),"")

So I want a formula which would extract string before the character mentioned in a single formula and not separate formula.

like image 829
Atul Patil Avatar asked Sep 11 '25 21:09

Atul Patil


2 Answers

It seems you were on the right track. Put one of the following standard formulas in E2,

=REPLACE(C2, MIN(FIND(".", C2&"."), FIND("_", C2&"_")), LEN(C2), TEXT(,))
=LEFT(C2, MIN(FIND(".", C2&"."), FIND("_", C2&"_"))-1)

Standard formula in F2 as,

=MID(C2, IFERROR(FIND("_", C2)+1, 1), FIND(".", C2)-IFERROR(FIND("_", C2)+1, 1))

Fill down as necessary.

    min_find_replace

Another way

=MID(C2,1,MIN(SEARCH(".",C2&"."),SEARCH("_",C2&"_"))-1)
like image 37
Karthick Gunasekaran Avatar answered Sep 13 '25 11:09

Karthick Gunasekaran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!