String help
Moderators: Dorian (MJT support), JRL
String help
I need to read from a set of strings, eg EBB21-Jason or EBB203-Jason but I want to be able to capture only the code in front (EBB21 and EBB203 respectively). Which means I would have to capture any characters before "-". What is the simplest way to do that? Do I use regex? I am not familiar with regex though.. Thanks
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You can either do it with simple substring handling:
Or quicker with RegEx:
See:
http://www.mjtnet.com/forum/post32883.html
Code: Select all
Let>example_string=EBB12-Jason
//get everything up to the "-"
Position>-,example_string,1,posHyphen
MidStr>example_string,1,{%posHyphen%-1},code_part
MessageModal>The code is %code_part%
Code: Select all
Let>example_string=EBB12-Jason
//get everything up to the "-"
RegEx>.*(?=\-),example_string,0,matches,nm,0
MessageModal>The code is %matches_1%
http://www.mjtnet.com/forum/post32883.html
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Small adjustment to cover either of "-", ":", or " ". Since you are new to RegEx, it is very powerful, but you have to be careful how you structure them so you don't get wrong results. The code below would work well for simple strings, starting with the ID. (If you have longer strings with several "-", ":" or " ", or the ID somewhere in the middle, you would get strange results and would have to modify the criteria.) You can find a free good tutorial to RegEx under
http://www.regular-expressions.info/
Let>example_string1=EBB12-Jason
//get everything up to the "-", ":", or " "
RegEx>.*(?=[-: ]),example_string1,0,matches,nm,0
If>nm>0
MessageModal>The code is %matches_1%
Endif
http://www.regular-expressions.info/
Let>example_string1=EBB12-Jason
//get everything up to the "-", ":", or " "
RegEx>.*(?=[-: ]),example_string1,0,matches,nm,0
If>nm>0
MessageModal>The code is %matches_1%
Endif