• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Help with RegExp conversion from PhP to VB

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?
thanks
Phil

0
philggg
Asked:
philggg
2 Solutions
 
pradapkumarCommented:
Please try this

regex.Pattern = "#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\" & chr(34) & chr(34) & _
    "]*)[\\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"


I hope this will help u.
0
 
mvidasCommented:
Hi Phil,

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

To:
 [\x00-\x20]

The rest of it looks syntactically correct at least.
Matt
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now