Solved

backslash character VBScript runtime error: Syntax error in regular expression

Posted on 2016-09-15
2
98 Views
Last Modified: 2016-09-15
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
0
Comment
Question by:Alex E.
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 41800071
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.
0
 

Author Closing Comment

by:Alex E.
ID: 41800107
Simply like that worked.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question