1

I have been using the function who as I found in this SO answer for finding variables in the workspace that match a string.

I have been trying without problem:

who('-regexp', 'signal');

That will return a list of variables containing the string 'signal', such as:

'signal'
'signal1'
'signal_RMS'
'signal1_RMS'

But I want to know how I can find variables adding exceptions, such as "exclude the variables that ends with '_RMS' ".

I tried including regular expressions as I found in Matlab documentation (regexp), with no luck, and the closer thing I found was something like this:

who('-regexp', 'signal(?!_RMS)');

But this will only exclude the variables 'signal' that are immediately follow by '_RMS',

'signal'
'signal1'
'signal1_RMS'

Any hint on how I can handle expressions to find variables such as "start with 'string', do not end up with 'otherstring' " ?

2
  • 1
    There are plenty of regex tutorials on the internet. I always found regexr helpful. Commented Jan 27, 2017 at 10:43
  • So you mean you need 'signal(?!.*_RMS$)'? Commented Jan 27, 2017 at 10:45

1 Answer 1

0

I want to know who can I find variables adding exceptions, such as "exclude the variables that ends with '_RMS' ".

The 'signal(?!_RMS)' pattern will find all signal substrings not immediately followed with _RMS. To make sure the strings do not end with _RMS, you need to allow any 0+ chars in between signal and _RMS and use the $ (end-of-string) anchor.

'signal(?!.*_RMS$)'

See the regex demo.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, I didn't know regex101.com, really useful! this solved my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.