在 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
广告
我们可以使用以下代码比较给定的字符串
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