"dongdong" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> for example:
>  re.sub('<a( [^>]+)+\s?>[^<^>]*</a>','',' asd ga<a target="_blank"
> href="http://www.sine.com"; class="wordstyle"> asdgasdghae rha</a>')
>
> I wish to get the return value "asd ga asdgasdghae rha",how do do?
> I have a impression on "%" and "{number}",but forgot how to use them.
>

Well, here's the pyparsing rendition (two, actually).  I hope it's easier to
follow then trying to pick apart the above regexp.  Both

Download pyparsing at http://pyparsing.sourceforge.net.

-- Paul


instr = """' asd ga<a target="_blank"
href="http://www.sine.com"; class="wordstyle"> asdgasdghae rha</a>'"""

from pyparsing import makeHTMLTags,Suppress,MatchFirst

# makeHTMLTags returns a tuple of the start and end pattern for the given
tag
aStart,aEnd = makeHTMLTags("a")

# define a filter that will suppress the opening and closing tags
# this is easily extended to filter additional patterns, too
filter = Suppress(aStart) | Suppress(aEnd)

# invoke transformString using the filter
print filter.transformString(instr)

# or for the dense-code minded...
filter = MatchFirst( map( Suppress, makeHTMLTags("a") ) )
print filter.transformString(instr)


Prints:
' asd ga asdgasdghae rha'
' asd ga asdgasdghae rha'


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to