backslash character VBScript runtime error: Syntax error in regular expression

Alex E.
Alex E. used Ask the Experts™
on
Hello I´m using a a VBscript to search 2 strings in the middle of one.

Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
oRE.Pattern = "\activ\(.*?)\vid"

Open in new window


In this test the script need to search for strings "\activ\" and "\vid"

Now I received the error when I run the VBscript via command prompt with cscript: "VBScript runtime error: Syntax error in regular expression"

Now I see the backslash "\" characters are not accepted to search in the string. I tested the script with letters and numbers including normal "/" and works but how can I modify the script to accept in the search string and search also "\" backslash characters?

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
Backslash is a reserved character, and you have to escape it with an extra backslash.  Like so:

oRE.Pattern = "\\activ\\(.*?)\\vid"

Open in new window


You may also be interested in this article on using the VBScript implementation of RegExp.

Author

Commented:
Simply like that worked.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial