普通的前pression匹配< A HREF ="邮寄地址:
问题描述:
我想匹配所有
<a href="mailto:abc@abc.com">bla bla bla</a>
和我还有一个过滤器,将追加
and I have another filter that will append
<a rel="email" href="mailto:abc@abc.com">bla bla bla</a>
所以,我在找正规前pression会发现,与替换功能。
So I am looking for the regular expression that will find that with the replace function.
答
请使用HTML解析器来代替。您还没有指定的语言,但这里的使用Python中BeautifulSoup示范:
Please use an html parser instead. You haven't specified a language, but here's a demonstration using BeautifulSoup in Python:
>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup('<a href="mailto:abc@abc.com">bla bla bla</a>')
>>> for a in soup.findAll('a'):
... a['rel'] = 'email'
...
>>> soup.prettify()
'<a href="mailto:abc@abc.com" rel="email">\n bla bla bla\n</a>'