On Jul 19, 3:04 am, Andrew Freeman <[EMAIL PROTECTED]> wrote: > let me revise it please: > > To show if valid: > > if re.search(r'^[LRM]*$', 'LM'): > print 'Valid'
Fine, this works, although match instead of search blah blah blah as has already been mentioned. I still think searching for one invalid character is more elegant then trying to match the entire string, but that's just personal preference, I guess. > > To show if invalid, > > if re.search(r'^[^LRM]*$', '0'): > print 'Inalid' No. This is wrong. This only matches strings that consist entirely of characters that are not L, R or M: >>> import re >>> if re.search(r'^[^LRM]*$', 'ZZZLZZZ'): ... print "Invalid" ... >>> This doesn't print "Invalid" because there is one non-invalid character there, which is clearly not what the OP wanted. -- http://mail.python.org/mailman/listinfo/python-list