Regular expression to match "="

조회 수: 2 (최근 30일)
Bruno Luong
Bruno Luong 2019년 9월 21일
댓글: Bruno Luong 2019년 9월 21일
In try to find a simple pattern p to match a single '=' but ignore '==' in a string
So I want
regexp('a = b', p)
to return 3
regexp('a == b', p)
to return [].
I try several things and they are all fail on '=='
>> regexp('a == b','=(?!=)')
ans =
4
>> regexp('a == b','={1}')
ans =
3 4
>> regexp('a == b','(?!==)=')
ans =
4
Any suggestion for simple pattern?

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 21일
regexp('a == b = d','(?<!=)=(?!=)')
This looks for = that are not preceded by = and not followed by =

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by