regexp match - not reading the hole name
Show older comments
Hello!
I have a list o parameters and a txt file containing some parameters. I have to check if what is in the txt file is also in my list of parameters. For this I used: [a b c]=regexp(my_list_of_parameters, parameter_from_txt_file,'match')
In general it works, the variable a will contain the found parameter. The problem is that when in my txt file I have this parameter named: parameter1 and my list of parameters contain a parameter named: parameter1aedfwef; by using the code above, Matlab will say that parameter1 from my txt file exists in my list of parameters. When searching after parameter1, Matlab finds parameter1aedfwef and it stops after 1! It is not taking into consideration the hole name of the parameter. This is not good because is not the same parameter! What should I use for avoiding this?
Accepted Answer
More Answers (1)
David Young
on 29 Nov 2011
Try using \<parameter1\> in the regular expression, instead of parameter1.
For example:
fileword = 'parameter1';
paramlist = 'parameter2, parameter1xyz, parameter3';
[a b c] = regexp(paramlist, ['\<' fileword '\>'], 'match')
This depends on parameter names being made of alphanumeric characters and underscore.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!