开发者

VB6 regular expression for whitespace remover in HTML

开发者 https://www.devze.com 2023-01-29 02:08 出处:网络
I\'m trying to run this regular expression [\\s]+(<)|(>)[\\s]+ dim myRegExp as object Set myRegExp = New RegExp

I'm trying to run this regular expression [\s]+(<)|(>)[\s]+

dim myRegExp as object
Set myRegExp = New RegExp
myRegExp.MultiLine = True
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "[\s]+(&l开发者_Python百科t;)|(>)[\s]+"
'myRegExp.Test (str)
str = myRegExp.Replace(str, "$2$1") 

this doesn't seem to work

you can test run that regular expression on http://www.regextester.com/ and it work perfectly

It's suppose to remove whitespace from the left and right of HTML Tags to optimize the webpage without removing whitespace in actual text just inbetween html tags.

<br>        adsfdf </br> <img    
asdddasd      >


sdfdsf <br>           <yah>43 3453490
90                             <tag>
<tag>

turns into

<br>adsfdf</br><img asdddasd>sdfdsf<br><yah>43 3453490 90<tag><tag>

why doesn't it work in VB6/VBScript? thanks


Try this instead:

myRegExp.Pattern = "\s+(<)|(>)\s+"
str = myRegExp.Replace(str, "$2$1")

VB6/VBScript regexes probably don't like \s in a character class.

0

精彩评论

暂无评论...
验证码 换一张
取 消