pete pete - 1 year ago 120
Python Question

Python: list and string matching

I have following:

temp = "aaaab123xyz@+"

lists = ["abc", "123.35", "xyz", "AND+"]

for list in lists
if re.match(list, temp, re.I):
print "The %s is within %s." % (list,temp)

The re.match is only match the beginning of the string, How to I match substring in between too.

Answer Source

You can use instead of re.match.

It also seems like you don't really need regular expressions here. Your regular expression 123.35 probably doesn't do what you expect because the dot matches anything.

If this is the case then you can do simple string containment using x in s.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download