tags:

views:

26

answers:

1

I have the following code in PHP:

    if (preg_match('@^[a-z0-9/._-]+$@i', $script)
      && !preg_match('@([.][.])|([.]/)|(//)@', $script))

I'm making the assumption that the predicate for the if statement returns true for the string js/core.js.

How would I translate this to C#? The dumb translation is as follows:

if(Regex.IsMatch(script,"@^[a-z0-9/._-]+$@i")
   && !Regex.IsMatch(script,"@([.][.])|([.]/)|(//)@"))

but I suspect that the @ symbol has meaning associated with it that I can't get to the bottom of. A translation to .NET regex would be nice, but I'm entirely familiar with .NET regex, so an explanation of the relevant syntax differences would suffice.

Many thanks.

+1  A: 

The @s are just delimiter. You don't need them in .NET

if(Regex.IsMatch(script,"^[a-z0-9/._-]+$", RegexOptions.IgnoreCase)
   && !Regex.IsMatch(script,"([.][.])|([.]/)|(//)"))
KennyTM
Awesome. My PHP-fu is very poor. I simply can't muster the enthusiasm to turn it around. ;)
spender