81,092
社区成员
发帖
与我相关
我的任务
分享
str.replace(/(id=\d+)/mg, "$1.html");
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String args[]) {
String[] array ={
"<a href=\"ViewDmwsjxx-in.do?id=76&mcname=花田家\">",
"<a href=\"ViewDmwsjxx-in.do?id=14&mcname=町町美食餐厅\">",
"<a href=\"ViewDmwsjxx-in.do?id=89&mcname=野妹火锅\">",
"<a href=\"ViewDmwsjxx-in.do?id=75&mcname=巴山小馆\">"};
Pattern pattern = Pattern.compile("(?<=id=)(\\d+)");
for (String str: array) {
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
System.out.println(matcher.replaceFirst(matcher.group(1)+".html"));
}
}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String args[]) {
String[] array = { "<a href=\"abc.do?id=1\">",
"<a href=\"aaaa.do?id=12\">", "<a href=\"121.do?id=13\">",
"<a href=\"4546.do?id=14\">", "<a href=\"a123.do?id=11\">" };
Pattern pattern = Pattern.compile("(?<=id=)(\\d+)");
for (String str: array) {
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
System.out.println(matcher.replaceFirst(matcher.group(1)+".html"));
}
}
}
}
String[] ss ={
"<a href=\"abc.do?id=1\">",
"<a href=\"aaaa.do?id=12\">",
"<a href=\"121.do?id=13\">",
"<a href=\"4546.do?id=14\">",
"<a href=\"a123.do?id=11\">"
};
Pattern pattern = Pattern.compile("(<a href=\"\\w+\\.do\\?id=\\d+){0}(\">)");
for(int i=0;i<ss.length;i++){
Matcher matcher = pattern.matcher(ss[i]);
ss[i]=matcher.replaceAll(".html\">");
System.out.println(ss[i]);
}
mport java.util.regex.*;
public class test{
public static void main(String args[]) {
String str="<a href=\"abc.do?id=1\">\n"
+"<a href=\"aaaa.do?id=12\">\n"
+"<a href=\"121.do?id=13\">\n"
+"<a href=\"4546.do?id=14\">\n"
+"<a href=\"a123.do?id=11\">";
String regex="(?im)(?<=[\\?]id=)(\\d+)";
str=str.replaceAll(regex,"$1.html");
System.out.println(str);
}
}