Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > regexp: match only if previous matched?

Reply
Thread Tools

regexp: match only if previous matched?

 
 
cirfu
Guest
Posts: n/a
 
      06-23-2008
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$".
 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      06-23-2008
On Jun 23, 6:02*pm, cirfu <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a pattern using a previous match and a count of the numberof '('s in it me Python 0 01-27-2009 12:02 PM
RegEx - matching previous match j ellings Perl Misc 4 02-28-2008 02:22 AM
RegEx - matching previous match j ellings Perl Misc 0 02-27-2008 10:12 PM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments