Regular expression to match "="

3 ビュー (過去 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 =
  1 件のコメント
Bruno Luong
Bruno Luong 2019 年 9 月 21 日
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by