Python uses a regular expression to match the start of a string and print the example. python Regular Expression
This example describes how to use a regular expression to match and print a string. We will share this with you for your reference. The details are as follows:
Import res = "name = z1hangshan username = fff url = www.baidu.com password = ddd256" s2 = "username = fff name = z1hangshan url = www.baidu.com password = ddd256" # p = re. compile (R '((? : \ S) name = (\ S) +) ') p = re. compile (R' (^ name = (\ S) +) ') iter = p. finditer (s) for m in iter: print "m", m. group () iter2 = p. finditer (s2) for m2 in iter: print "m2", m2.group () # m username = fff # m2 Mismatch
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg