Simple regular-expression example. : search « Regular Expressions « Python Tutorial






import re

# list of strings to search and expressions used to search
testStrings = [ "Hello World", "Hello world!", "hello world" ]
expressions = [ "hello", "Hello", "world!" ]

# search every expression in every string
for string in testStrings:
   for expression in expressions:
      if re.search( expression, string ):
         print expression, "found in string", string
      else:
         print expression, "not found in string", string
   print








16.5.search
16.5.1.Finding Numbers
16.5.2.Finding the Extension
16.5.3.Handling Different Separators
16.5.4.Handling Numbers Without Separators
16.5.5.Handling Leading Characters
16.5.6.Phone Number, Wherever I May Find Ye
16.5.7.Simple regular-expression example.