Knowing the Regular Expression-capabilities and -syntax of Perl, I wanted to have a similar syntax from within my VBScript code. VBScript uses the RegExp object, so I wrapped the calls to the RegExp object inside three function.
function rxTest( text, pattern, flags )
Use this function to test for a pattern inside a string. Acts similar to the
"http://www.perldoc.com/perl5.6/pod/perlre.html">=~ s// operator in Perl.
The arguments are:
textpatternflagsi: case insensitive, g: global, m: multilineReturns true if found, false if not found.
function rxReplace( text, pattern, replace_text, flags )
Use this function to replace a pattern inside a string with another string. Acts similar to the
"http://www.perldoc.com/perl5.6/pod/perlre.html">=~ m// operator in Perl.
The arguments are:
textpatternreplace_textflagsi: case insensitive, g: global, m: multilineReturns the modified string. The input-string is not modified by this function.
function rxExec( text, pattern, flags )
Use this function to test for a pattern inside a string and return the
matched elements. Acts similar to the
"http://www.perldoc.com/perl5.6/pod/perlre.html">=~ s// operator in Perl.
The arguments are:
textpatternflagsi: case insensitive, g: global, m: multilineReturns a
"http://msdn.microsoft.com/scripting/vbscript/doc/vscolmatches.htm">Matches collection if a match is found, otherwise returns nothing.
dim is_absolute
is_absolute = rxTest( url, "^(https|http|ftp|mailto|javascript|jscript)://", "gis" )
dim blank
blank = rxReplace( html, "<"&tag_name&"\b[^>]*>", "", "gi")
do
set matches = rxExec(html, "oid://([0-9]+)", "g")
if not IsNothing(matches) then
if matches.Count>0 then
set match = matches(0)
dim replacement
if match.SubMatches.Count>0 then
replacement = GetNameFromDatabaseByID(match.SubMatches(0))
else
replacement = ""
end if
html = Replace(html, match.Value, replacement)
else
exit do
end if
else
exit do
end if
loop
The last example uses the function IsNothing which is defined as followed:
function IsNothing( byref obj )
IsNothing = CBool(LCase(TypeName(obj))="nothing")
end function
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||