正则表达式子收集

参考链接:http://www.cnblogs.com/yirlin/archive/2006/04/12/373222.html 1.public static void main(String[] args) { String s = "GET /index.html HTTP/1.1";//字符串s由“GET”、“/index.html”和“HTTP/1.1”组成,中间有一个或多个空格 String tt[] = s.split("\\s{1,}");//按照空格分割字符串,多个空格作为一个空格对字符串进行分割 for(String str: tt)//增强的for循环 System.out.println(str);//输出:GET // /index.html // HTTP/1.1 String qq = s.replaceAll(" {2,}"," ");//把字符串s中的多个空格替换为一个空格 System.out.println(qq);//输出:GET /index.html HTTP/1.1 System.out.println(s);//输出:GET /index.html HTTP/1.1 } } 注解:"\\s{1,}",\s 表示空格 \* 表示 * 2. 截取间的********* String str = "声音通道,你好**********声音通道,你好************你好"; String tt[] = str.split("[^\\*]+");// 3.判断包含URLhttp://blog.csdn.net/ty0415/article/details/7974887 public static void main(String[] args) { // Todo Auto-generated method stub String strContent = "请到以下地址查询查询地址:充值地址:https://pay.sdo.com/Index.aspx?type=card尊敬的用户: 您好,该卡帐号和密码是正确的,请到以下https://pay.sdo.com/Index.aspx?type=card 地址查询查询地址:充值地址:https://pay.sdo.com/Index.aspx?type=card "; String regex = "(http:|https:)//[^[A-Za-z0-9\\._\\?%&+\\-=/#]]*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(strContent); StringBuffer result = new StringBuffer(); while (matcher.find()) { String urlStr = matcher.group(); StringBuffer replace = new StringBuffer(); replace.append("<a href=\"").append(urlStr); replace.append("\" target=\"_blank\">" + urlStr + "</a>"); matcher.appendReplacement(result,replace.toString()); } matcher.appendTail(result); System.out.println(result); }

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...