Home >Backend Development >Python Tutorial >Python uses regular expression to match the beginning of a string and print example
The example in this article describes how python uses regular expressions to match the beginning of a string and print it. Share it with everyone for your reference, the details are as follows:
import re s="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 不匹配
I hope this article will be helpful to everyone in Python programming.
For more Python using regular expressions to match the beginning of a string and print examples, please pay attention to the PHP Chinese website!