Home  >  Article  >  Backend Development  >  Python uses regular expression to match the beginning of a string and print example

Python uses regular expression to match the beginning of a string and print example

高洛峰
高洛峰Original
2017-01-12 16:41:151667browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn