ASP 정규식 사용하여 html 태그중 "<title>페이지 타이틀영역</title>" 을 추출한다.
제목 : ASP 정규식 사용하여 html 태그중 "<title>페이지 타이틀영역</title>" 을 추출한다.
<%
Set regEx = New RegExp ' 정규식을 작성합니다.
regEx.IgnoreCase = True ' 대/소문자 구분 안함을 설정합니다.
regEx.Global = True ' 전역을 설정합니다.
html = "aldskfja;dsfjka;dsfjka;fkjakldfjasdf<br>aljdsfhalfhalfjhalf<br><span>asdfasdfadsf</span><img src=""http://i2.media.daumcdn.net/photo-media/201104/15/ned/20110415101809573.jpg"" width=""500"" height=""646"" id=""1"">ㅁㄴ러미ㅏㅇ러마ㅣㄴㄹㅇ러<span>aksjdhfalkdfhlk</span><br><img src=""http://i2.media.daumcdn.net/photo-media/201104/15/ned/20110415101809573.jpg"" width=""500"" height=""646"" id=""2""><title>타이틀영역</title><font color='red'>-</font><title>타이틀영역2</title>"
''' 1. 이미지 태그만 가져오기
'regEx.Pattern = "<img [^<>]*>" ' 패턴을 설정합니다. 1,2,3,4,5 에 해당
regEx.Pattern = "<title[^ ]*</title>" '6에 해당
Set Matches = regEx.Execute(html) ' 찾기를 실행합니다.
'RetStr = ""
'RetImgPath = ""
'RetWidth = ""
'RetHeight = ""
'RetId = ""
RetTitle = ""
For Each Match in Matches ' Matches 컬렉션을 반복합니다.
'RetStr = RetStr & "<br>" & Replace(Match.Value, "<", "<") & vbcrlf
'RetImgPath = RetImgPath & GetImgSrc(Match.Value, "src=""") & "<br>"
'RetWidth = RetWidth & GetImgSrc(Match.Value, "width=""") & "<br>"
'RetHeight = RetHeight & GetImgSrc(Match.Value, "height=""") & "<br>"
'RetId = RetId & GetImgSrc(Match.Value, "id=""") & "<br>"
RetTitle = RetTitle & Match.Value & "<br>"
RetTitle = Replace(RetTitle, "<", "<") 'html 보여주기위함
RetTitle = Replace(RetTitle, ">", ">") 'html 보여주기위함
Next
'Response.Write "1. 이미지 태그만 가져오기<br>" & RetStr & "<br><br><br>"
'Response.Write "2. 이미지 경로만 가져오기<br>" & RetImgPath & "<br><br><br>"
'Response.Write "3. 이미지 가로길이만 가져오기<br>" & RetWidth & "<br><br><br>"
'Response.Write "4. 이미지 세로길이만 가져오기<br>" & RetHeight & "<br><br><br>"
'Response.Write "5. 이미지 ID값만 가져오기<br>" & RetId & "<br><br><br>"
Response.Write "6. TITLE 가져오기<br>" & RetTitle & "<br><br><br>"
Function GetImgSrc(strImgTag, strAttr)
'strImgTag = <img src="asdfasdfaf.jpg" width="123" height="333" id="adsfasdf" />
'strAttr = src=", width="
Dim imgsrc, filepath
imgsrc = mid(strImgTag, instrRev(strImgTag, strAttr) + Len(strAttr))
filepath = left(imgsrc, instr(imgsrc, """")-1)
GetImgSrc = filepath
End Function
%>
내용 :
function GetImgSrc 는 사용안함. 주석처리는 이미지관련 처리.
출처 :