SoFunction
Updated on 2025-03-02

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

This article describes the method of using regular expressions to match the beginning of a string and print it. Share it for your reference, as follows:

import re
s="name=z1hangshan username=fff url= password=ddd256"
s2="username=fff name=z1hangshan url= password=ddd256"
#p=(r'((?:\s)name=(\S)+)')
p=(r'(^name=(\S)+)')
iter=(s)
for m in iter:
  print "m", ()
iter2=(s2)
for m2 in iter:
  print "m2", ()
#m username=fff
#m2 mismatch

PS: Here are two very convenient regular expression tools for your reference:

JavaScript regular expression online testing tool:
http://tools./regex/javascript

Regular expression online generation tool:
http://tools./regex/create_reg

For more information about Python, please view the special topic of this site: "Summary of Python regular expression usage》、《Python data structure and algorithm tutorial》、《Summary of Python Socket Programming Tips》、《Summary of Python function usage tips》、《Summary of Python string operation skills》、《Python introduction and advanced classic tutorials"and"Summary of Python file and directory operation skills

I hope this article will be helpful to everyone's Python programming.