Why do strfind and regexp may lead to a different result?

조회 수: 7 (최근 30일)
pietro
pietro 2017년 6월 12일
댓글: pietro 2017년 6월 13일
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
pietro
pietro 2017년 6월 12일
pardon, I pasted the wrong example.
Stephen23
Stephen23 2017년 6월 12일
편집: Stephen23 2017년 6월 12일
@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:

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
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
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.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by