RE Question

tiefeng wu icebergwtf at gmail.com
Sun Aug 2 22:33:53 EDT 2009


2009/8/3 Victor Subervi <victorsubervi at gmail.com>:
-> Hi;
-> How do I search and replace something like this:
> aLine = re.sub('[<]?[p]?[>]?<font size="h' + str(x) + '"[
> a-zA-Z0-9"\'=:]*>[<]?[b]?[>]?', '<h' + str(x) + '>', aLine)
> where RE *only* looks for the possibility of "<p>" at the beginning of the
> string; that is, not the individual components as I have it coded above, but
> the entire 3-character block?
> TIA,
> Victor

I'm not sure I totally understand your problem, try this:
aLine = re.sub(r'(?:<p>)?<font
size="h{0}"[^>]*>(?:<b>)'.format(str(x)), '<h' + str(x) + '>', aLine)

tiefeng wu
2009-08-03



More information about the Python-list mailing list