Why do strfind and regexp may lead to a different result?
Show older comments
Hi all,
I noticed that regexp and strfind may lead to different results. Here an example:
regexp('Infinitely Variable Transmission (IVT)','Infinitely Variable Transmission (IVT)')
Why does it occur?
Thanks
3 Comments
Adam
on 12 Jun 2017
What is that an example of?
>> regexp('Infinitely Variable Transmission','Infinitely Variable Transmission')
ans =
1
>> strfind('Infinitely Variable Transmission','Infinitely Variable Transmission')
ans =
1
pietro
on 12 Jun 2017
@pietro: if you are planning on using regular expressions then you really need to understand the different meta-characters, such as parentheses. A good place to learn about regular expressions in MATLAB is to read the MATLAB documentation:
Accepted Answer
More Answers (1)
Walter Roberson
on 12 Jun 2017
1 vote
In the general case, regexp can return different results if the pattern includes metacharacters.
There is a routine that can be used to "escape" characters so that they are treated literally, but the routine name is not coming to mind at the moment.
1 Comment
Walter Roberson
on 12 Jun 2017
regexptranslate() with the 'escape' option is suitable for this purpose.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!