将c#regex转换为javascript正则表达式 [英] Convert c# regex to javascript regex

查看:88
本文介绍了将c#regex转换为javascript正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#reg ex可以使用以下正则表达式:

The following regular expression is workable using C# reg ex:


^(?< survey># 。_surveyForm +)|#(?:?(小于URL> HTTP + \.\w {3,4})+ _ surveyForm = \w +)$

它匹配字符串,例如:

#http://localhost/tableaux-p145717.htm=&_surveyForm=second

#_surveyForm=second

我使用了命名捕获组。

我知道Javascript没有利用命名捕获组(而是使用\ 1,\\\等等) )。除此之外,语法与上面的语法略有不同。

I know Javascript doesn't take advantage of named capturing groups (instead it uses \1, \2, etc.). Besides the syntax is slightly different from the one above.

如何使该reg符合javascript标准?

How can I make that reg ex javascript-compliant?

提前致谢,

R。

推荐答案

当你说,JavaScript不支持命名捕获。您必须将它们更改为正常捕获组,并按编号而不是按名称引用它们:

As you said, JavaScript doesn't support named captures. You have to change those into "normal" capturing groups and refer to them by number instead of by name:

/^(#_surveyForm.+)|#(?:(http.+\.\w{3,4}).+_surveyForm=\w+)$/

你还应该知道 \w 只匹配JavaScript中的ASCII字母数字,而它与.NET中的Unicode字母匹配。

You should also be aware that \w only matches ASCII alphanumerics in JavaScript whereas it matches Unicode alnums in .NET.

这篇关于将c#regex转换为javascript正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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