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.
The @
s are just delimiter. You don't need them in .NET
if(Regex.IsMatch(script,"^[a-z0-9/._-]+$", RegexOptions.IgnoreCase)
&& !Regex.IsMatch(script,"([.][.])|([.]/)|(//)"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With