在 Python 中使用正则表达式比较两个字符串?


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

示例

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

更新于: 2019 年 12 月 19 日

1K+ 浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告