JavaScript 正则表达式规则正在破坏 ASP.NET 缩小

标签 javascript asp.net regex

我有这个功能,它在所有浏览器中都能正常工作:

    cleanKey = function( key ){
        return key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
    };

但是,我的 ASP.NET MVC 3 项目在尝试缩小该代码时抛出正则表达式语法错误:

run-time error JS5017: Syntax error in regular expression
/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g

最佳答案

您可能想尝试 \u037f 而不是 \u37f 因为 MSDN specifies :

\xn
Matches n, where n is a hexadecimal escape value.
Hexadecimal escape values must be exactly two digits long.
For example, '\x41' matches "A".   '\x041' is equivalent to '\x04' & "1".
Allows ASCII codes to be used in regular expressions.

\un
Matches n, where n is a Unicode character expressed as four hexadecimal digits.
For example, \u00A9 matches the copyright symbol (©).

此外,我想知道,这是一个有效范围吗:\xf8-\u037d(根据 asp.net 缩小工具)?
您可能想试试 \u00f8-\u037d
(也许添加 \xf8-\xff 以补偿本地化代码页的上半部分与该地区的 Unicode 之间的差异。)

希望这对您有所帮助。

关于JavaScript 正则表达式规则正在破坏 ASP.NET 缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16093598/

相关文章:

c# - 使用循环限制并发异步请求

c# - C# 中的分隔嵌套括号

使用 Vala 和 GLib 的正则表达式

javascript - 如何为特定浏览器导入脚本 Ember-CLi Broccoli

javascript - 无法解析不同文化的日期

asp.net - 交易明细中的Paypal数量错误

asp.net - 如何制作没有文件扩展名的 ASPX 网页?

javascript - 如何监控用户在线状态(实时)

javascript - 当两个复选框位于同一页面上使用相同的类名时,如何使用 nightjs 选中我想要的复选框?

regex - vscode 正则表达式子匹配评估而不是连接?