regexp: match only if previous matched?

Discussion in 'Python' started by cirfu, Jun 23, 2008.

  1. cirfu

    cirfu Guest

    I need to extract prices froma html-document.

    [0-9]*\$ matches 112$ 45$ etc but also just a $. why that shouldnt
    really matter and it is unlikely anyway to appear a $sign with no
    price attahced to it I still want to prevent it.

    How do I avoid matching "$"? It has to be "nbr$".
    cirfu, Jun 23, 2008
    #1
    1. Advertising

  2. cirfu

    Carl Banks Guest

    On Jun 23, 6:02 pm, cirfu <> wrote:
    > I need to extract prices froma html-document.
    >
    > [0-9]*\$ matches 112$ 45$ etc but also just a $. why that shouldnt
    > really matter and it is unlikely anyway to appear a $sign with no
    > price attahced to it I still want to prevent it.
    >
    > How do I avoid matching "$"? It has to be "nbr$".


    The answer to your question is to use a + instead of *. + matches 1
    or more elements, * matches zero or more.

    The second point to mention is that, at least where I come from, the
    currency symbol comes before the number:

    $112 and $45

    In which case your regexp should be somehting like this: \$[0-9]+


    Carl Banks
    Carl Banks, Jun 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mikel Lindsaar
    Replies:
    0
    Views:
    479
    Mikel Lindsaar
    Mar 31, 2008
  2. Old Echo
    Replies:
    1
    Views:
    180
    Adam Shelly
    Sep 4, 2008
  3. Jean Nibee
    Replies:
    4
    Views:
    197
    lasitha
    Apr 13, 2009
  4. Joao Silva
    Replies:
    16
    Views:
    354
    7stud --
    Aug 21, 2009
  5. Uldis  Bojars
    Replies:
    2
    Views:
    190
    Janwillem Borleffs
    Dec 17, 2006
Loading...

Share This Page