[Java] 正则表达式替换文字 符号 →→→→→进入此内容的聊天室

来自 , 2019-09-23, 写在 Java, 查看 101 次.
URL http://www.code666.cn/view/9f396fe4
  1. String str = "Java目前的发展史是由{0}年-{1}年";
  2. String[][] object={new String[]{"\\{0\\}","1995"},new String[]{"\\{1\\}","2007"}};
  3. System.out.println(replace(str,object));
  4.  
  5. public static String replace(final String sourceString,Object[] object) {
  6.             String temp=sourceString;    
  7.             for(int i=0;i<object.length;i++){
  8.                       String[] result=(String[])object[i];
  9.                Pattern    pattern = Pattern.compile(result[0]);
  10.                Matcher matcher = pattern.matcher(temp);
  11.                temp=matcher.replaceAll(result[1]);
  12.             }
  13.             return temp;
  14. }

回复 "正则表达式替换文字 符号"

这儿你可以回复上面这条便签

captcha