preg_match与.NET等效 [英] preg_match to .NET equivalent

查看:62
本文介绍了preg_match与.NET等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中具有以下代码:

I have the following code in PHP:

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

我假设 if 语句的谓词对于字符串 js/core.js 返回true.

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

我如何将其翻译为C#?愚蠢的翻译如下:

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

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

但是我怀疑 @ 符号具有与之相关的含义,我无法深入了解它.可以将.NET regex转换为.NET regex,但我完全熟悉.NET regex,因此对相关语法差异的解释就足够了.

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.

非常感谢.

推荐答案

@ 只是分隔符.您在.NET中不需要它们

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

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

这篇关于preg_match与.NET等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆