Why do strfind and regexp may lead to a different result?
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Adam
2017 年 6 月 12 日
編集済み: Adam
2017 年 6 月 12 日
regexp( 'Infinitely Variable Transmission (IVT)', 'Infinitely Variable Transmission \(IVT\)' )
works, but you have to escape the parenthesis as they have special meaning in a regexp expression.
if you look in
doc regexp
in the section headed 'Split Text at Delimiter Using split Keyword', there is an example of this for escaping the ^ symbol.
その他の回答 (1 件)
Walter Roberson
2017 年 6 月 12 日
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 件のコメント
Walter Roberson
2017 年 6 月 12 日
regexptranslate() with the 'escape' option is suitable for this purpose.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!