주요 함수는 다음과 같습니다. HTML 문자열에서 IMG 태그 SRC의 값을 바꾸십시오.
코드는 다음과 같습니다.
package com.junlenet.common.util; import java.util.regex.matcher; import java.util.regex.pattern;/*** html 처리 도구 클래스* @author huweijun* @date 2016 년 7 월 13 일 오후 7 월 13 일 오후*/public class htmlutils {/* value and galling and gally and gloatified and galling and gally htmlutils. @param str string을 처리 할* @param tagtag name* @param tagattrib 교체 할 태그 속성 값* @param starttag 새 태그 시작 태그* @param endtag new tag end tag* @return* @author huweijun* @date 2016 년 7 월 13 일 오후 13 일, String strathttib, string stringhttmltag. starttag, string endtag) {String regxpfortag = "<// s*" + tag + "// s + ([^>]*) // s*"; String regxpfortagattrib = tagattrib + "= // s*/"([^/"] +)/"; 패턴 Patternag = PatternPile (regxpfortag, Pattern.Scase _insensitive); (regxpfortagattrib, pattern.case_insensitive); matcher matcherfortag = patternfortag.matcher (str); stringbuffer sb = boolean result = matcherfortag.find (); patternforattrib.matcher (matcherfortag.find); matcherfortag.appendReplacement (sb, sbreplace.toString ()); class =/"imgbox/"> <li> <img id =/"160424/"src =/"uploads/allimg/160424/1-160424120t1-50.jpg/"class =/"src_class/"> </li> "); content.append ("<li> <img id =/"150628/"150628/"150628/"150628/" src =/"업로드/allimg/150628/1-15062q12247.jpg/"class =/"src_class/"> </li> </ul> "); System.out.println ("원래 문자열은 "+content.toString ()); String Newstr = replacthtmltag (imptring)". "src", "src =/"http://junlenet.com/ ","/"");Java 일반 스크립트의 IG 태그에서 SRC 값을 대체하는 위의 방법은 내가 공유 한 모든 컨텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.