Hello,

I wonder if someone could tell me where I am going wrong with my regular expression, please. My regex only matches the text I'm looking for (a number followed by a distance unit) when it appears at the beginning of the string. But I am not using the ^ character (which would indicate that I only want a match if it is at the start).

-------------------------------
#
import re

regex1 = re.compile("[0-9]+ (feet|meters)", re.IGNORECASE)

def is_distance(str):
   if regex1.match(str):
      print "distance"
   else:
      print "not distance"

# First one matches, second does not -- WHY?
is_distance("300 feet is the distance")
is_distance("The distance is 300 feet")
-------------------------------

Thank you!

J-C

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to