regexp: match only if previous matched?

C

cirfu

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$".
 
C

Carl Banks

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top