String str = "ffafd&#test1;afafdi&#test2;&#test3;1344343...."; String patternStr = "#([^&;]*?);"; // Compile regular expression Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(str); while (matcher.find()) { // Get the match result String replaceStr = matcher.group(); // this is what you want replaceStr = replaceStr.replaceAll(patternStr,"$1"); // for test System.out.println(replaceStr); }
String patternStr = "#([^&;]*?);";
// Compile regular expression
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
// Get the match result
String replaceStr = matcher.group();
// this is what you want
replaceStr = replaceStr.replaceAll(patternStr,"$1");
// for test
System.out.println(replaceStr);
}
{
/**
* @param args
*/
public static void main(String[] args)
{
java.util.regex.Pattern p=java.util.regex.Pattern.compile("&#([^&]*);");
java.util.regex.Matcher m=p.matcher("ffafd&#test1;afafdi&#test2;&#test3;1344343");
java.util.List list=new java.util.ArrayList();
while(m.find())
{
System.out.println(m.group(1));
list.add(m.group(1));
}
Object[] s=list.toArray();
for(int i=0;i<s.length;i++)
System.out.println(s[i]);
}
}
Pattern p=Pattern.compile("&#[^&#;]+;");
Matcher m=p.matcher(str);
while(m.find()) System.out.println(m.group().replaceAll("[&#;]",""));