Skip to content

Instantly share code, notes, and snippets.

@icella
Created June 20, 2019 02:18
Show Gist options
  • Save icella/98ed543be9babc0ca506d547e6722296 to your computer and use it in GitHub Desktop.
Save icella/98ed543be9babc0ca506d547e6722296 to your computer and use it in GitHub Desktop.
去掉字符串中的html标签的正则表达式
//定义script的正则表达式,去除js可以防止注入
String scriptRegex="<script[^>]*?>[\\s\\S]*?<\\/script>";
//定义style的正则表达式,去除style样式,防止css代码过多时只截取到css样式代码
String styleRegex="<style[^>]*?>[\\s\\S]*?<\\/style>";
//定义HTML标签的正则表达式,去除标签,只提取文字内容
String htmlRegex="<[^>]+>";
//定义空格,回车,换行符,制表符
String spaceRegex = "\\s*|\t|\r|\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment