Help with RegExp conversion from PhP to VB

Posted on 2006-04-02
Last Modified: 2010-04-07
I am transfering over a regular expresion from php to VB (I am using it to block cross site scripting on a web page)
The original php epresion is:
$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*expression[\x00-\x20]*\([^>]*>#iU',"$1>",$string);

My VB version using RegExp
regex.Pattern = "#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\""]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iU"
oldstring = regex.Replace(oldstring, "$1=$2nojavascript...>")
(note I replaced the single apostrophe with a double)
I get a very unhelpful error from VB:
Application-defined or object-defined error

Two questions:
What is wrong with my pattern?
How do I get more helpful error messages out of RegExp?

Question by:philggg
    LVL 9

    Assisted Solution

    Please try this

    regex.Pattern = "#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\" & chr(34) & chr(34) & _

    I hope this will help u.
    LVL 35

    Accepted Solution

    Hi Phil,

    I noticed your 3rd block of hex 0-20 has two \ symbols, that should only be one:


    The rest of it looks syntactically correct at least.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now