Regular expression to match "="
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Walter Roberson
2019-9-21
regexp('a == b = d','(?<!=)=(?!=)')
This looks for = that are not preceded by = and not followed by =
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!