Python regex:<a> tag

时间:2019-03-07 08:22:37

标签: regex python-3.x

I know I got BeautifulSoup, But I want to try my own.

Regex I've been working on

之间的文本
<br>This Text needed
<a>unwanted text</a>
<br/>
This text needed
<a >unwanted text</a>
 This text needed
<a>unwanted text</a>
<br>this text needed

我想出了什么:

(</a>|(<br(/>|>)))(\s.*|\w.*)

我想匹配This text needed,但其中之一不匹配。

1 个答案:

答案 0 :(得分:0)

以这种方式,先行否定后退积极

(?<!<a>)This Text needed(?!<\/a>)

演示: https://regex101.com/r/RT5LZu/1