package com.shawn.util; import lombok.extern.slf4j.Slf4j; import org.elasticsearch.search.suggest.completion.RegexOptions; import java.util.regex.Matcher; import java.util.regex.Pattern; @Slf4j public class DelHtmlUtil { private static final String regEx_pre = "]*?>[\\s\\S]*?<\\/pre>"; // 定义pre的正则表达式 private static final String regEx_script = "]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式 private static final String regEx_style = "]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式 private static final String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式 private static final String regEx_space = "\\s*|\t|\r|\n";//定义空格回车换行符 private static final String regEx_img_src = "]*?>";//定义img的正则表达式 /** * @param htmlStr * @return 删除Html标签 */ public static String delHTMLTag(String htmlStr) { Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE); Matcher m_script = p_script.matcher(htmlStr); htmlStr = m_script.replaceAll(""); // 过滤script标签 Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE); Matcher m_style = p_style.matcher(htmlStr); htmlStr = m_style.replaceAll(""); // 过滤style标签 Pattern p_pre = Pattern.compile(regEx_pre, Pattern.CASE_INSENSITIVE); Matcher m_pre = p_pre.matcher(htmlStr); htmlStr = m_pre.replaceAll(""); // 过滤pre标签 Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); Matcher m_html = p_html.matcher(htmlStr); htmlStr = m_html.replaceAll(""); // 过滤html标签 // Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE); // Matcher m_space = p_space.matcher(htmlStr); // htmlStr = m_space.replaceAll(""); // 过滤空格回车标签 return htmlStr.trim(); // 返回文本字符串 } /** * 获取 第一个 img 的src * @param htmlStr * @return */ public static String getFirstImgSrc(String htmlStr){ Pattern p_script = Pattern.compile(regEx_img_src, Pattern.CASE_INSENSITIVE); Matcher m_image = p_script.matcher(htmlStr); while (m_image.find()) { // 得到数据 String img = m_image.group(); // 匹配中的src数据 Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img); while (m.find()) { return m.group(1); } } return ""; } public static String getTextFromHtml(String htmlStr) { htmlStr = delHTMLTag(htmlStr); htmlStr = htmlStr.replaceAll(" ", ""); return htmlStr; } // public static void main(String[] args) { // String str = "ubuntu 安装 phpmyadmin 两种 (两者选一):\n" + // "

1: apt-get 安装 然后使用 已有的虚拟主机目录建立软连接

\n" + // "
\n" + // "
    \n" + // " \t
  1. sudo apt-get install phpmyadmin
  2. \n" + // " \t
  3. sudo ln-s /usr/share/phpmyadmin/ /var/www/pma
  4. \n" + // "
\n" + // "
\n" + // "

2:手动上传

\n" + // "网上下载 phpmyadmin软件包,使用 filezilla 上传到 /var/www/pma (pma自己创建)\n" + // "\n" + // "使用 ip/pma 查看 phpmyadmin\n" + // "\n" + // "其实 还可以 考虑给phpmyadmin 配置虚拟主机\n" + // "\n" + // "接下来 配置MySQL的 remote access\n" + // "\n" + // "默认下 mysql只能是本机访问的 但是 如果我通过ip 远程 访问方式 就是 remote access 比如 我在其他机器上要使用navicate 访问 也属于 remote access\n" + // "\n" + // "但是 ubuntu中的mysql 默认是不允许的 所以要修改mysql的配置\n" + // "\n" + // "sudo vim /etc/mysql/my.cnf #修改 bind-address 白名单 取消掉\n" + // "\n" + // "\"\"\n" + // "

\n" + // "

进入phpmyadmin

\n" + // "查看 用户 添加一个用户 可以 用 公网的ip 访问:\n" + // "\n" + // "\"\"\n" + // "\n" + // "\"\"\n" + // "

重启msyql

\n" + // "
\n" + // "
    \n" + // " \t
  1. sudo service mysql restart
  2. \n" + // "
\n" + // "
\n" + // "使用navicate测试远程登录:\n" + // "\n" + // "\"\"\n" + // "\n" + // "\"\"\n" + // "\n" + // "以上 远程登录 已经 完成\n" + // "\n" + // " \n" + // "\n" + // "更多文章\n" + // "\n" + // "ubuntu14.04 下 mysql 存储目录迁移\n" + // "\n" + // "ubuntu14.04下配置apache虚拟主机\n" + // "\n" + // "ubuntu14.04 安装phpmyadmin 和配置\n" + // "\n" + // " \n" + // "\n" + // " \n" + // "\n" + // "本文地址:http://liuyanzhao.com/2447.html\n" + // "\n" + // "转载请注明\n" + // "\n" + // " "; // System.out.println(getTextFromHtml(str)); // System.out.println(getFirstImgSrc(str)); // } }