String str= " <td align= 'center '> aaaaa </td> ";
String r= "( <td align= 'center '> )(.*)( </td> ) ";
Pattern s=Pattern.compile(r);
Matcher m = s.matcher(str);
如上,在java里面我想用变量获取其中aaaaa的值,请问我应该怎么做呢?
------解决方案--------------------
public static String test(String str){
Pattern pattern = Pattern.compile( " <[^ <|> ]*> ");
//Pattern pattern1 = Pattern.compile( " ");
Matcher matcher = pattern.matcher(str);
String returnStr = matcher.replaceAll( " ");
//Matcher matcher1 = pattern.matcher(returnStr);
return returnStr;
}
------解决方案--------------------
String str= " <td align= 'center '> aaaaa </td> ";
String r = "( <td align= 'center '> )(.*)( </td> ) ";
System.out.println(str.replaceAll(r, "$2 "));
------解决方案--------------------
String str= " <td align= 'center '> aaaaa </td> ";
String r= "( <td align= 'center '> )(.*)( </td> ) ";
Pattern s=Pattern.compile(r);
Matcher m = s.matcher(str);
String s1=m.group(1);
就可以了