Using Regular Expressions

Hello, Given an arbitrary string str(e.g. 'AAAAAAA'), if I want to find the regular expression pattern pat='A.A' (i.e. an 'A' followed by any character followed by another 'A'), then regexp(str,pat) returns locations 1 and 4 for the example string although the same pattern can be observed at location 2,3 and so on. Is there a way of finding all the locations? Thanks.

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 21일

0 개 추천

No, not without a "while" or "for" loop.
However, if you change your pattern to pat = 'A(?=.A)' then you would get what you were hoping for.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2011년 12월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by