Click here to Skip to main content
Email Password   helpLost your password?

Introduction

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.

Functions

rxTest

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:

Returns true if found, false if not found.

rxReplace

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:

Returns the modified string. The input-string is not modified by this function.

rxExec

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:

Returns a "http://msdn.microsoft.com/scripting/vbscript/doc/vscolmatches.htm">Matches collection if a match is found, otherwise returns nothing.

Examples

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.
 
 
Per page   
 FirstPrevNext
GeneralThis is a _slow_solution
Anonymous
4:49 31 Oct '01  
I believe this helps beginners to use regex.
This solution will however create a new regex
object for every search/replace.

If you call these functions from within a loop,
your code will be at least 10 times slower
than code that uses a single regex object,
instantiated outside the loop.

Creating one COM object takes 15 times longer than
replacing all characters in a 100 byte line using
regex.

Suspicious You should stick with the MS architecture, or
create a class file with private object vars.

Bambi@CrackDealer.com

Generalexecuting a script
Konstantin S. Diguine
23:55 24 Jul '01  
How to make the following: the program receives some VBScript then executes it upon itself (the same instance)? The program is OLE-server.

konst
GeneralRe: executing a script
Uwe Keim
0:01 25 Jul '01  
How is this related to my article?

Anyway, Windows Script 5.6 has such sort of functionality. Check out http://msdn.microsoft.com/scripting.

---
See me: www.magerquark.de
Generalregex
Anonymous
21:58 23 Jul '01  
the file regex is come to unix and linux by regex.h.

this not a vb utility very new !!!
Red faced


Last Updated 28 Aug 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010