Regular expressions, builing up a simple expression for a search

1 view (last 30 days)
Hello All,
I am stuck with a regular expression and I would appreciate your help. I want to list some specific cases from some simulations. For instance, I have the following case names:
...
wkxr4_75_ind1_350_0.inf
wkxr4_75_ind4_400_0.inf
swxr4_75_ind3_420_0.inf
wkxr4_75_cap1_350_0.inf
stxr4_75_cap2_400_0.inf
wkxr4_75_cap5_420_0.inf
...
Until now I just needed to do something simple, like getting the cases that started with sw, or wk, or st:
^(sw|wk|st)
However, now I want to find of those cases, the ones that also contain 400_0 and 420_0
I undertand the $ character can be used to give me the end, and it could work with something like this, right?
$(400_0.inf|420_0.inf)
The complete expression would be something like this below. However, I tried several different variations without success. For instance using [a-z_]+. etc.
'^(sw|wk|st) 'something here?' $(400_0.inf|420_0.inf)'
Thanks in advance!
Best regards,
Adriel Perez

Accepted Answer

Adam Danz
Adam Danz on 18 Jul 2019
Edited: Adam Danz on 18 Jul 2019
I recommend that site when building regular expressions.
^(sw|wk|st).+(400_0\.inf|420_0\.inf)$
% ^ start ^^ ^ ^ ^
% ^^ ^ ^ ^ end
% ^^ anything in between
% ^ .........^ escape characters (\) for decimal points
  2 Comments
Guillaume
Guillaume on 18 Jul 2019
Another way to write the end of that regular expression would be:
'^(sw|wk|st).+4[02]0_0\.inf$'
And the .+ could be .* depending on whether or not you want something between the two expressions.

Sign in to comment.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!