classes and special sequences. : Match : Regular Expressions PYTHON TUTORIALS


PYTHON TUTORIALS » Regular Expressions » Match »

 

classes and special sequences.


import re

testStrings = "2x+5y","7y-3z" ]
expressions = r"2x+5y|7y-3z",r"[0-9][a-zA-Z0-9_].[0-9][yz]", r"dw-dw" ]

for expression in expressions:
   for testString in testStrings:
      if re.matchexpression, testString ):
         print expression, "matches", testString

testString1 = "000-123-4567"
testString2 = "111-123-4567"
testString3 = "email: t joe_doe@deitel.com"

expression1 = r"^d{3}-d{3}-d{4}$"
expression2 = r"w+:s+w+@w+.(com|org|net)"

if re.matchexpression1, testString1 ):
   print expression1, "matches", testString1

if re.matchexpression1, testString2 ):
   print expression1, "matches", testString2

if re.matchexpression2, testString3 ):
   print expression2, "matches", testString3



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Regular Expressions
» Match