Regular expression question

Hello,

I have file names such as:

WT 1.lsm
WT 2.lsm
WT 2 b.lsm
MUT 1.lsm

And I only want to extract WT or MUT.

In theory I think this should work?!

    ^(?P<Treatment>.*\s).*\s?.*.lsm

The idea of the (\s?) is that there might (or might not) be another space, following the first one.
But it stil gives WT 2 instead of WT for the WT 2 b.lsm filename.
Could you tell me the correct syntax?

This works:
^(?P<Treatment>[A-Z]{2,3})\s.*.lsm

I tend to use regex101 to play with the different regex, but certainly there are other tools out there.

Good luck!

2 Likes

Thank you very much. This works!

1 Like

I cannot get a simple regular expression to work.

metadata does have channelname matching ^340

does not work for a channelname called 340.

I’ve even doubled checked the regex101, which says my regular expression ^340 or ^[3-40]{3} should work.

What am I missing?

Question moved here: Regular Expression in NamesAndTypes module

1 Like