Comments on: How to avoid VBScript regular expression gotchas http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: James Guo http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/#comment-38408 James Guo Tue, 23 Apr 2013 07:05:58 +0000 http://www.xaprb.com/blog/?p=36#comment-38408 “(.|\n)*” ,that works best for multiline match!
Thank the guys above!

]]>
By: Demon http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/#comment-19800 Demon Tue, 27 Dec 2011 06:54:09 +0000 http://www.xaprb.com/blog/?p=36#comment-19800 “When Multiline is True, the meaning of the . metacharacter is different; it then matches every character including a newline.”

I don’t think this is right, it can be tested using the following code:

str = “hello” & vbCrLf & “world”
Set re = New RegExp
re.MultiLine = True
re.Pattern = “.+”
Set ms = re.Execute(str)
WScript.Echo ms(0) = “hello” & vbCr
‘echo -1 whether MultiLine property is set to True or not.

]]>
By: JakFrost http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/#comment-18807 JakFrost Thu, 21 Oct 2010 00:48:03 +0000 http://www.xaprb.com/blog/?p=36#comment-18807 Yes, VBscript.RegExp pattern matching is very broken and doesn’t follow the POSIX standard at all for the “.” any-character.

I just spent an hour slamming my head against a wall trying to parse a multiline string that is the body of an e-mail. Until I realized that “.*” does not work for matching new lines, with .MultiLine set or unset. Using the character set “[.\n]*” did not work either. Only the wrong solution of using alternation “(.|\n)*” worked.

POSIX | VBScript
“.*” ~= “(.|\n)*”

]]>
By: David Gray http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/#comment-17514 David Gray Wed, 30 Dec 2009 02:50:14 +0000 http://www.xaprb.com/blog/?p=36#comment-17514 Your observation follows from mine about the way the VBScript RegExp object treats newlines. While this behavior has the theoretical advantage that it allows you to treat carriage return (\r) and line feed (\n) characters separately, most of the time, such treatment is counterintuitive.

]]>
By: Scriptar http://www.xaprb.com/blog/2005/11/04/vbscript-regular-expression-gotchas/#comment-15568 Scriptar Tue, 16 Dec 2008 18:44:01 +0000 http://www.xaprb.com/blog/?p=36#comment-15568 re #2 from the article:
“Backslashed special characters do not work correctly inside brackets. For example, it ought to be possible to match across newlines with the patterns [.\n]* and [.\s]*, but this prevents the pattern from matching anything at all, even when no newlines are involved.”

I was able to get this to work by using the following pattern:
regEx.Pattern = “(.|[\r\n])*”

…also using a lazy quantifier:
regEx.Pattern = “(.|[\r\n])*?”

It’s not great but it works if you’re stuck with VBScript.

]]>