如何使用 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
廣告
我們可以使用以下程式碼比較給定的字串
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