在 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