在 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+ 瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.