2016-06-16 3 views
1

나는 img 태그를 html로 가지고 있습니다. Regex를 사용하여 img 태그를 얻었습니다. 나는 약간의 코드를 작성했고 내 코드는 하나의 img 태그에서만 작동하고있다.<img> 태그에서 이미지 추출 src android

String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"; 

     Pattern p = Pattern.compile(imgRegex); 
     Matcher m = p.matcher(htmlString); 

     if (m.find()) { 
      String imgSrc = m.group(1); 

      String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/tanadgomaaa"; 
      String imagePath = "file://"+ base + "/test.jpg"; 
      imgSrc=imgSrc.replace(imgSrc,imagePath); 



     } 

내가 어떻게 img 태그를 html 문자열에서 가져올 수 있는지 말해 줄 수 있습니까? 감사

당신은 내가 내 문제를 해결할 수있는 방법을 말해 줄 수 engineer14 @
+0

예? – engineer14

+0

도움이 될 것입니다에서 그것을 얻으려고 노력하는 문자열의 – donoachua

+0

나는 당신이 사용하고있는 언어 ('java'?)에 익숙하지 않지만 캐릭터의 각 버전을 분류하는 것이 아니라 정규 표현식에 사용할 수있는 대소 문자를 구분하지 않는 수정자를 가지고 있다고 생각한다. 아마도 모든 이미지를 꽤 쉽게 가져올 수있는 파서가있을 것입니다. – chris85

답변

1
String imgRegex = "(?i)<img[^>]+?src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"; 

    Pattern p = Pattern.compile(imgRegex); 
    Matcher m = p.matcher(htmlString); 

    while(m.find()) { 
     String imgSrc = m.group(1); 

     String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/tanadgomaaa"; 
     String imagePath = "file://"+ base + "/test.jpg"; 
     imgSrc=imgSrc.replace(imgSrc,imagePath); 



    } 
관련 문제