java 正则替换 域名/ip和端口
public String replaceDomainAndPort(String domain,String port,String url){ String url_bak = ""; if(url.indexOf("//") != -1 ){ String[] splitTemp = url.split("//"); url_bak = splitTemp[0]+"//"; if(port != null){ url_bak = url_bak + domain+":"+port; }else{ url_bak = url_bak + domain; } if(splitTemp.length >=1 && splitTemp[1].indexOf("/") != -1){ String[] urlTemp2 = splitTemp[1].split("/"); if(urlTemp2.length > 1){ for(int i = 1;i < urlTemp2.length; i++){ url_bak = url_bak +"/"+urlTemp2[i]; } } System.out.println("url_bak:"+url_bak); }else{ System.out.println("url_bak:"+url_bak); } } return url_bak; }
String replaceUrl=replaceDomainAndPort("192.168.10.196","81",laborCompanyRelated.getPhotoPath());
js正则替换url的域名/ip和端口
url = url.replace(/^https:\/\/[^/]+\//, "https://192.168.10.196:81/");
url = url.replace(/^http:\/\/[^/]+\//, "http://192.168.10.196:81/");
记录一下,方便后续使用