trying to match a string
John Machin
sjmachin at lexicon.net
Sat Jul 19 01:32:15 EDT 2008
On Jul 19, 12:04 pm, Andrew Freeman <alif... at gmail.com> wrote:
> To show if valid:
>
> if re.search(r'^[LRM]*$', 'LM'):
> print 'Valid'
>
A couple of points:
(1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...)
(2) You need to choose your end-anchor correctly; your pattern is
permitting a newline at the end:
>>> re.search(r'^[LRM]*$', 'LM\n')
<_sre.SRE_Match object at 0x00B9E528>
>>>
More information about the Python-list
mailing list