/** * * @Title: findByIdChengStr * @Description: TODO * @author 凱哥Java * @param editContentStr * @return * @return String * @throws */ private String findByIdChengStr(String str,String Vpath) { String [] pathArr = Vpath.split(","); String regStr1 = "<ure>([\\s\\S]*?)</ure>"; Pattern r1 = Pattern.compile(regStr1); Matcher m1 = r1.matcher(str); List<VoidBean> listBean = new ArrayList<VoidBean>(); while(m1.find()){ String oldStr = m1.group(0); listBean.add(new VoidBean(0,0,null,m1.group(0))); } for (int i = 0; i <listBean.size(); i++) { StringBuilder sbs = new StringBuilder(str); VoidBean bean = listBean.get(i); String preStr = bean.getOldStr(); String url = preStr.substring(0,preStr.length()-2); String beannewStr =pathArr[i];// bean.getNewStr(); String oldStr = bean.getOldStr(); int length = str.indexOf(oldStr);//由於是從開始計數,因此加1 int end = length+url.length()+2;//取得結束位置 String newStr = "<pre>"+beannewStr+"</pre>"; sbs.replace(length, end, newStr); str= sbs.toString(); } return str;java /** String regStr = "<video ([\\s\\S]*?) </video>"; String urlStr = "src=\"([\\s\\S]*?)\""; Pattern r = Pattern.compile(regStr); Pattern urlr = Pattern.compile(urlStr); Matcher m = r.matcher(str); List<VoidBean> listBean = new ArrayList<VoidBean>(); while(m.find()){ String oldStr = m.group(0); // System.out.println("oldStr:"+oldStr); //<video src="http://10.10.10.242:82/kaigejava/roadshow/product4.mp4" poster="" controls="controls" preload="metadata" webkit-playsinline="webkit-playsinline" type="video/mp4" > </video> Matcher mUrl = urlr.matcher(oldStr); if(mUrl.find()){ String url = mUrl.group(0); // System.out.println("url:"+url); // src="http://10.10.10.242:82/kaigejava/roadshow/product4.mp4" url=url.substring(5, url.length()-1); // System.out.println("處理後的url:"+url); //處理後的url:http://10.10.10.242:82/kaigejava/roadshow/product4.mp4 listBean.add(new VoidBean(0,0,url,m.group(0))); } } for (int i = 0; i <listBean.size(); i++) { StringBuilder sbs = new StringBuilder(str); VoidBean bean = listBean.get(i); String preStr = bean.getOldStr(); String url = preStr.substring(0,preStr.length()-2); String beannewStr = bean.getNewStr(); String oldStr = bean.getOldStr(); int length = str.indexOf(oldStr);//由於是從開始計數,因此加1 int end = length+url.length()+2;//取得結束位置 String newStr = "<pre>"+beannewStr+"</pre>"; sbs.replace(length, end, newStr); str= sbs.toString(); } return str; **/ } web |