Mistake in documentation for regexp?

Even after using MATLAB for 20 years, I still need to look at the doc for this function from time to time. This time I noticed something that I missed over the years. I believe this has been in there since at least ver 7.
The first example under the documentation for regexp is shown below, with highlighting added. However, the expression given does not perform to the specification. For example, compare the highlighted specs with the results from using this string:
str = 'bat cat can car coat court CUT ct CAT-scan haircuts';
Of course regexp found the 'cut' in haircuts, which is a word that neither starts with a 'c' nor ends with a 't'. Maybe it's pedantic, maybe not. Perhaps it's just worded in such a way that it may lead someone astray. In any case, take this as an FYI and maybe an invitation to update the wording of this example.

댓글 수: 1

dpb
dpb 2026년 3월 12일 20:18
Yeah, agree, the use of "word" instead of "string" or "substring" is an incorrect description of the problem solved.
There are two choices; fix the doc to match the actual search or add the additional condition to the search that the 'c' and 't' must be the first and last letters in a word (preceded/followed by whitespace, respectively).

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

답변 (1개)

Walter Roberson
Walter Roberson 2026년 3월 12일 20:53

0 개 추천

The description is wrong; the pattern used is looking for substrings, not "words".
str = 'bat cat can car coat court CUT ct CAT-scan haircuts';
expression1 = 'c[aeiou]+t';
expression2 = '\<c[aeiou]+t\>'
expression2 = '\<c[aeiou]+t\>'
startIndex1 = regexp(str, expression1)
startIndex1 = 1×3
5 17 48
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
startIndex2 = regexp(str, expression2)
startIndex2 = 1×2
5 17
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

댓글 수: 1

dpb
dpb 2026년 3월 13일 15:23
I think the ideal fix would be to show both examples...

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

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2026년 3월 12일 19:00

댓글:

dpb
2026년 3월 13일 15:23

Community Treasure Hunt

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

Start Hunting!

Translated by