how to express the following regular expression?
Carl Howells
chowells at cs.uoregon.edu
Wed Nov 21 04:47:36 EST 2001
"Stephen" <fungho at sinaman.com> wrote...
> I want to search the following formats:
>
> ([1234567890]*)R
> or
> P([1234567890]*)
>
> this means there must be a 'P' before the number or a 'R' after the
> number. However, I think I can't use this:
> P?([1234567890]*)R?
> because the number without P and R is also matched!
>
> How can I express it?
Exactly you you'd expect... One or the other:
(P\d*)|(\d*R)
You could also use [0-9] in place of \d, if you were really set on using the
[] notation. But there's no reason to use [1234567890].
More information about the Python-list
mailing list