如何使用 Python 中的 regex 比较两个字符串?


我们可以使用以下代码比较给定的字符串

示例

import re
s1 = 'Pink Forest'
s2 = 'Pink Forrest'
if bool(re.search(s1,s2))==True:
   print 'Strings match'
else:
   print 'Strings do not match'

输出

输出结果如下

Strings do not match

更新于:19-Dec-2019

1K+ 次浏览

开启您的职业生涯

完成课程,获得认证

开始
广告
© . All rights reserved.