|
|
@ -1653,18 +1653,34 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit |
|
|
|
* @author zxc |
|
|
|
* @date 2022/7/1 10:32 |
|
|
|
*/ |
|
|
|
public static String getPreviewContent(String content) { |
|
|
|
if (StringUtils.isBlank(content)){ |
|
|
|
return ""; |
|
|
|
} |
|
|
|
String regex = "[\\u4e00-\\u9fa5]"; |
|
|
|
Pattern p = Pattern.compile(regex); |
|
|
|
Matcher m = p.matcher(content); |
|
|
|
StringBuffer sb = new StringBuffer(); |
|
|
|
while (m.find()) { |
|
|
|
sb.append(m.group()); |
|
|
|
} |
|
|
|
return sb.toString(); |
|
|
|
public String getPreviewContent(String content) { |
|
|
|
// 定义script的正则表达式
|
|
|
|
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; |
|
|
|
// 定义style的正则表达式
|
|
|
|
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; |
|
|
|
// 定义HTML标签的正则表达式
|
|
|
|
String regEx_html = "<[^>]+>"; |
|
|
|
//定义空格回车换行符
|
|
|
|
String regEx_space = "\\s*|\t|\r|\n"; |
|
|
|
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE); |
|
|
|
Matcher m_script = p_script.matcher(content); |
|
|
|
// 过滤script标签
|
|
|
|
content = m_script.replaceAll(""); |
|
|
|
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE); |
|
|
|
Matcher m_style = p_style.matcher(content); |
|
|
|
// 过滤style标签
|
|
|
|
content = m_style.replaceAll(""); |
|
|
|
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); |
|
|
|
Matcher m_html = p_html.matcher(content); |
|
|
|
// 过滤html标签
|
|
|
|
content = m_html.replaceAll(""); |
|
|
|
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE); |
|
|
|
Matcher m_space = p_space.matcher(content); |
|
|
|
// 过滤空格回车标签
|
|
|
|
content = m_space.replaceAll(""); |
|
|
|
//去空格
|
|
|
|
content = content.replaceAll(" ", ""); |
|
|
|
return content.trim(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|