且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将c#regex转换为javascript正则表达式

更新时间:2023-02-21 14:28:43

当你说,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.