java ssm禁止ip_SSM博客实战(1)--正则表达式去除html标签

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class Demo {

private static final String regEx_script = "

private static final String regEx_style = "

private static final String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式

private static final String regEx_space = "\\s*|\t|\r|\n";//定义空格回车换行符

/**

* @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_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(); // 返回文本字符串

}

public static String getTextFromHtml(String htmlStr){

htmlStr = delHTMLTag(htmlStr);

htmlStr = htmlStr.replaceAll(" ", "");

htmlStr = htmlStr.substring(0,100);

return htmlStr;

}

public static void main(String[] args) {

String str = "ubuntu 安装 phpmyadmin  两种 (两者选一):\n" +

"

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

"

\n" +

"

  1. \n" +

" \t

sudo  apt-get install  phpmyadmin\n" +

" \t

sudo  ln-s /usr/share/phpmyadmin/      /var/www/pma\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" +

"

  1. \n" +

" \t

sudo  service  mysql restart\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));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值