首先,先上我的图例,最近被分配的任务,清洗某张千万级别的表,所以就碰到了下面的问题了,下面上才艺吧!!!

String regEx_script="]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style="]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html= "(?!<(img|A|a).*?>)(?!<\\/(img|A|a).*?>)<.*?>";//定义HTML标签的正则表达式
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
Matcher m_script=p_script.matcher(licenceContent);
licenceContent=m_script.replaceAll(""); //过滤script标签
Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
Matcher m_style=p_style.matcher(licenceContent);
licenceContent=m_style.replaceAll(""); //过滤style标签
Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
Matcher m_html=p_html.matcher(licenceContent);
licenceContent=m_html.replaceAll(""); //过滤html标签
当然我这里是保留了img和a标签,没有为什么,只是个人需要~~~所以还是在附上个不保留的吧!!!
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
本文分享了一种针对千万级别数据表的清洗方法,通过使用正则表达式精确过滤HTML标签,同时保留img和a标签,确保数据清洗的准确性和效率。
26万+

被折叠的 条评论
为什么被折叠?



