grouping and greedy operations. : Group : Regular Expressions PYTHON TUTORIALS


PYTHON TUTORIALS » Regular Expressions » Group »

 

grouping and greedy operations.


import re

formatString1 = "%-22s: %s"   # string to format output 

testString1 = "phone: 123-4567, e-mail: a@server.com"
expression1 = r"(w+ w+), phone: (d{3}-d{4}), e-mail: (w+@w+.w{3})"

formatString2 = "%-38s: %s"   # string to format output

pathString = "/books/2001/python"  # file path string

expression2 = "(/.+)/"  # greedy operator expression
print formatString1 % "Greedy error",re.matchexpression2, pathString ).group) )

expression3 = "(/.+?)/"  # non-greedy operator expression
print formatString1 % "No error, base only",re.matchexpression3, pathString ).group) )



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Regular Expressions
» Group