[Python] python正则表达式match、search使用实例 →→→→→进入此内容的聊天室

来自 , 2019-08-30, 写在 Python, 查看 115 次.
URL http://www.code666.cn/view/41d6c248
  1. import re
  2. def testsearchandmatch():
  3.   s1="helloworld, i am 30 !"
  4.  
  5.   w1 = "world"
  6.   m1 =  re.search(w1, s1)
  7.   if m1:
  8.     print("find : %s" % m1.group())
  9.    
  10.   if re.match(w1, s1) == none:
  11.     print("cannot match")
  12.    
  13.   w2 = "helloworld"
  14.   m2 = re.match(w2, s1)
  15.   if m2:
  16.     print("match : %s" % m2.group())
  17. testsearchandmatch()
  18. #find : world
  19. #cannot match
  20. #match : helloworld
  21. #//python/8474

回复 "python正则表达式match、search使用实例"

这儿你可以回复上面这条便签

captcha