简体   繁体   English

正则表达式选择HTML标记内的特定字符

[英]Regex to select specific characters inside HTML tags

I'm only looking for standard tags like p, title, h1, h2 etc. 我只是在寻找像p,title,h1,h2等标准标签。

<[/a]*>content resides in here</[/a]*>

And I'm specifically looking for punctuation marks to combat a potential SQL injection. 我特意寻找标点符号来对抗潜在的SQL注入。 Also, for this project I am unable to use BeautifulSoup. 此外,对于这个项目,我无法使用BeautifulSoup。

Try this regex: 试试这个正则表达式:

<(a|h1|p|title)[^>]*>([^<]+)</\1[^>]*>

Discussion 讨论

正则表达式可视化

Demo 演示

http://regex101.com/r/mB4bQ1 http://regex101.com/r/mB4bQ1

Discussion 讨论

I assume that tags will contain text only, no tags... 我假设标签只包含文本,没有标签......
Python doesn't support recursive regular expression. Python不支持递归正则表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM