Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Get Text Between HTML PRE Tags
;*************************************************************************** ;** RegExp Sample ;** Use Regular Expressions to locate the text inside HTML PRE tags ;** ;*************************************************************************** oRegex = ObjectCreate ("VBScript.RegExp") oRegex.Global = 1 oRegex.Multiline = 1 oRegex.IgnoreCase = 1 retval = "nothing" sTxt = "<HTML><HEAD>RegExp Sample</HEAD><BODY>Hello World<P><PRE>Predefined Text 1</PRE><P>Welcome to the world of Regular Expressions<PRE>Predefined Text 2</PRE></BODY></HTML>" oRegex.Pattern = "<pre>((?:.|\n|\r)*?)</pre>" If oRegex.Test(sTxt) retval = "" objMatches = oRegex.Execute(sTxt) ForEach objMatch In objMatches ;Each item in the SubMatches collection is the string found and captured by the regular expression. ForEach objSubMatch In objMatch.SubMatches If retval == "" Then retval = objSubMatch Else retval = retval : @TAB : objSubMatch Next Next EndIf AskItemlist("RegExp - Pre Tag Matches", retval, @TAB, @UNSORTED, @SINGLE ) oRegex = 0 ;Close object Exit
;*************************************************************************** ;** RegExp Sample ;** Use Regular Expressions to locate the text inside the FIRST HTML PRE tag ;** ;*************************************************************************** oRegex = ObjectCreate ("VBScript.RegExp") oRegex.Global = 1 oRegex.Multiline = 1 oRegex.IgnoreCase = 1 retval = "" sTxt = "<HTML><HEAD>RegExp Sample</HEAD><BODY>Hello World<P><PRE>Predefined Text 1</PRE><P>Welcome to the world of Regular Expressions<PRE>Predefined Text 2</PRE></BODY></HTML>" oRegex.Pattern = "<pre>((?:.|\n|\r)*?)</pre>" If oRegex.Test(sTxt) Then retval = oRegex.Execute(sTxt).item(0).SubMatches.item(0) Message ("RegExp - Pre Tag First Match", retval) oRegex = 0 ;Close object Exit
objRE = ObjectCreate ("VBScript.RegExp") objRE.Global = 1 objRE.Multiline = 1 objRE.IgnoreCase = 1 ; Version 1. strResult = "" objRE.Pattern = "<pre>((?:.|\n|\r)*?)</pre>" If objRE.Test(strHtml) objMatches = objRE.Execute(strHtml) ForEach objMatch In objMatches ForEach objSubMatch In objMatch.SubMatches strResult = strResult : objSubMatch Next Next EndIf Message ("Result 1", strResult) ; Version 2. strResult = "" objRE.Pattern = "<pre>((?:.|\n|\r)*?)</pre>" If objRE.Test(strHtml) Then strResult = objRE.Execute(strHtml).item(0).SubMatches.item(0) Message ("Result 2", strResult) ; Trim leading and trailing carriage-return and line-feed characters. objRE.Pattern = "^(?:\r|\n)+|(?:\r|\n)+$" strResult = objRE.Replace(strResult, "") Message ("Result 3", strResult) ; Change American Date to ISO-8601 Date. Prepend "20" for years within the 21st century. objRE.Pattern = "(\d\d)/(\d\d)/(\d\d)" strResult = objRE.Replace(strResult, "20$3-$1-$2") Message ("Result 4", strResult) ; How many items? intCount = ItemCount (strResult, @LF) Message ("Result 5", "Items = " : intCount) objRE = 0 Exit
Article ID: W18164
Filename: Get Text Between PRE Tags.txt
File Created: 2012:10:26:10:14:34
Last Updated: 2012:10:26:10:14:34