Compiled regular-expression and match objects. : Match : Regular Expressions PYTHON TUTORIALS


PYTHON TUTORIALS » Regular Expressions » Match »

 

Compiled regular-expression and match objects.


import re

testString = "Hello world"
formatString = "%-35s: %s"   # string for formatting the output

expression = "Hello"
compiledExpression = re.compileexpression 

print formatString % "The expression", expression )
print formatString % "The compiled expression",compiledExpression )

print formatString % "Non-compiled search",re.searchexpression, testString ) )
print formatString % "Compiled search",compiledExpression.searchtestString ) )

print formatString % "search SRE_Match contains",re.searchexpression, testString ).group() )
print formatString % "compiled search SRE_Match contains",compiledExpression.searchtestString ).group() )



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Regular Expressions
» Match