Regular Expressions

Bob Lancaster boblancaster at zxmail.com
Tue Apr 27 10:47:48 EDT 2004


"Robert Brewer" <fumanchu at amor.org> wrote in message news:<mailman.21.1082993871.25742.python-list at python.org>...
> sjf wrote:
> > I would like to please to help me with build a regular expression.
> > There are following piece of html code in my files:
> > 
> > <FONT COLOR="#FF0000">A - TYPE1: any text<BR>
> > B - TYPE2: any text 2<BR>
> > C - TYPE2: any text 3<BR>
> > w - any text 15<BR>
> > </FONT>
> > html code
> > </BODY></HTML>
> > 
> > I need to have only following data:
> > (B, any text 2)
> > (C, any text 3)
> > that is, these data TYPE2 in which.
> 
> If you can guarantee that every TYPE2 is on its own line with the same
> formatting:
> 
> >>> s = '<FONT COLOR="#FF0000">A - TYPE1: any text<BR>\nB - TYPE2:
> any text 2<BR>\nC - TYPE2: any text 3<BR>\nw -
> any text 15<BR>\n</FONT>\nhtml code'
> >>> import re
> >>> re.findall(r'(?m)^(.) - TYPE2: (.*)<BR>$', s)
> [('B', 'any text 2'), ('C', 'any text 3')]
> 
> 
> Robert Brewer
> MIS
> Amor Ministries
> fumanchu at amor.org


Thank you for this post.  I am working on a completely different
project, and this information was quite helpful for me in dealing with
formatted output.

-Bob Lancaster

rlancasterATbruker-axsDOTcom



More information about the Python-list mailing list