Regular Expression Help

John Machin sjmachin at lexicon.net
Sun Apr 12 01:40:00 EDT 2009


On Apr 12, 2:19 pm, ru... at yahoo.com wrote:
> On Apr 11, 9:42 pm, Jean-Claude Neveu <jcn-france1... at pobox.com>
> wrote:
>
> > My regexp that I'm matching against is: "^\$\£?\d{0,10}(\.\d{2})?$"
>
> > Here's how I think it should work (but clearly
> > I'm wrong, because it does not actually work):
>
> > ^\$\£?      Require zero or one instance of $ or £ at the start of the string.
>
> The "or" in "$ or £" above is a vertical bar.  You
> want ^(\$|£)? here.

Best not to use a capturing group (blah) when you don't need to
capture ... use (?:blah) instead.

When the alternatives are all single characters, for greater typing
efficiency and computing efficiency use a character class:

^[\$£]?



More information about the Python-list mailing list