Help with SplitString to extract sample name out of file name

I have a series of waves with the following names:

FeCl2_x0.000_y0.000_10.00s_96470_saxs.dat
FeCl2_x0.000_y0.000_10.00s_96471_saxs.dat
FeCl2_x0.000_y0.000_10.00s_96472_saxs.dat

etc.

 

I want to extract the "FeCl2" out of the corresponding string (I used WaveList and StringFromList), i.e., anything after the first underscore I do not care about. 

How does that translate to the regExprStr in the SplitString function? Or perhaps anoter approach would be more efficient?

 

Thanks for your help

AG

 

Hi,

One way is to use stringfromlist again.  let's assume the string is filename such as FeCl2_x0.000_y0.000_10.00s_96470_saxs.dat

Then:

String text_you_want

text_you_Want= stringfromlist(0,filename,"_")// 0 is index, i.e. first, filename is the original string, and "_" says use underscore as the delimiter in the list.

 

Andy

Assuming that you do not know the FeCl2 in advance

^([a-z,A-Z,0-9])+

This will return the first "word" up to the underscore.

Yeah!

I got one right!  With this lockdown, I take whatever I can get.

Andy