regexp: match only if previous matched?

Vlastimil Brom vlastimil.brom at
Tue Jun 24 00:12:56 CEST 2008

2008/6/24, cirfu <circularfunc at>:
> 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$".
> --
In this simple case you can simple use something like:


ie. at least one digit immediately folowed by a dollar-sign

If you really needed to check for a preceding text, look into

look-behind assertions of the form  (?<=...) or (?<!...) (negative)



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list