regexp: match only if previous matched?
Vlastimil Brom
vlastimil.brom at gmail.com
Mon Jun 23 18:12:56 EDT 2008
2008/6/24, cirfu <circularfunc at yahoo.se>:
>
> 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$".
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
In this simple case you can simple use something like:
[0-9]+\$
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)
cf. http://docs.python.org/lib/re-syntax.html
hth,
vbr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080624/617d21a4/attachment-0001.html>
More information about the Python-list
mailing list