av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python正則表達式的幾種匹配方法

我們在計算機應用方面經常會遇到很多的困難,例如下面列出Python正則表達式,就Python正則表達式中經常出現(xiàn)的問題我們給出以下的幾種匹配用法,希望大家在這篇文章中對Python正則表達式有一個更好的了解。

創(chuàng)新互聯(lián)建站主營昆山網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,重慶APP開發(fā),昆山h5微信小程序開發(fā)搭建,昆山網(wǎng)站營銷推廣歡迎昆山等地區(qū)企業(yè)咨詢

1.測試正則表達式是否匹配字符串的全部或部分

 
 
 
  1. regex=ur"" #正則表達式
  2. if re.search(regex, subject):
  3. do_something()
  4. else:
  5. do_anotherthing()

2.測試正則表達式是否匹配整個字符串

 
 
 
  1. regex=ur"\Z" #正則表達式末尾以\Z結束
  2. if re.match(regex, subject):
  3. do_something()
  4. else:
  5. do_anotherthing()

3.創(chuàng)建一個匹配對象,然后通過該對象獲得匹配細節(jié)(Create an object with details about how the regex matches (part of) a string)

 
 
 
  1. regex=ur"" #正則表達式
  2. match = re.search(regex, subject)
  3. if match:
  4. # match start: match.start()
  5. # match end (exclusive): atch.end()
  6. # matched text: match.group()
  7. do_something()
  8. else:
  9. do_anotherthing() 

4.獲取正則表達式所匹配的子串(Get the part of a string matched by the regex)

 
 
 
  1. regex=ur"" #正則表達式
  2. match = re.search(regex, subject)
  3. if match:
  4. result = match.group()
  5. else:
  6. result = "" 

5. 獲取捕獲組所匹配的子串(Get the part of a string matched by a capturing group)

 
 
 
  1. regex=ur"" #正則表達式
  2. match = re.search(regex, subject)
  3. if match:
  4. result = match.group"groupname")
  5. else:
  6. result = "" 

6. 獲取有名組所匹配的子串(Get the part of a string matched by a named group)


當前文章:Python正則表達式的幾種匹配方法
分享URL:http://uogjgqi.cn/article/dpcpcop.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流