3초기억력

ASP - 정규식을 이용한 html 중 img 태그만 추출 본문

플밍_ASP

ASP - 정규식을 이용한 html 중 img 태그만 추출

잠수콩 2011. 4. 15. 12:35
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


제목 : 정규식을 이용한 html 중 img 태그만 추출


'**************************************************

'*** 정규식으로 이미지만 뽑아내기 제거

'**************************************************

    Set regEx = New RegExp              ' 정규식을 작성합니다.

    regEx.IgnoreCase = True             ' 대/소문자 구분 안함을 설정합니다.

    regEx.Global = True                 ' 전역을 설정합니다.

 

 

    ''' 1. 이미지 태그만 가져오기

    regEx.Pattern = "<img [^<>]*>"      ' 패턴을 설정합니다.

    Set Matches = regEx.Execute(html)   ' 찾기를 실행합니다.

 

    RetStr = ""

 

    For Each Match in Matches   ' Matches 컬렉션을 반복합니다.

        RetStr = RetStr & "<br>" & Replace(Match.Value, "<", "&lt;") & vbcrlf

    Next

 

    Response.Write "1. 이미지 태그만 가져오기<br>" & RetStr & "<br><br><br>"

 ''' 2. 이미지 경로와 이미지명 가져오기
   regEx.Pattern = "[^= ']*\.(gif|jpg|bmp)"
   Set Matches = regEx.Execute(html)   ' 찾기를 실행합니다.

   RetStr = ""

   For Each Match in Matches   ' Matches 컬렉션을 반복합니다.
       RetStr = RetStr & "<br>" & Match.Value & vbcrlf
   Next

   Response.Write "2. 이미지 경로와 이미지명 가져오기<br>" & RetStr & "<br><br><br>"


   ''' 3. 이미지명만 가져오기
   regEx.Pattern = "[^= '/]*\.(gif|jpg|bmp)"
   Set Matches = regEx.Execute(html)   ' 찾기를 실행합니다.

   RetStr = ""

   For Each Match in Matches   ' Matches 컬렉션을 반복합니다.
       RetStr = RetStr & "<br>" & Match.Value & vbcrlf
   Next

   Response.Write "3. 이미지명만 가져오기<br>" & RetStr & "<br><br><br>"
 


내용 : html editor 로 넘어온 '내용' 글 중 img 태그만 추출 하는 것




Comments