gpt4 book ai didi

javascript - 为 javascript 转义 .NET 正则表达式模式

转载 作者:行者123 更新时间:2023-11-30 18:32:39 25 4
gpt4 key购买 nike

(ASP).NET 库中是否有任何辅助函数可以正确转义要在 javascript 中使用的 .NET 正则表达式模式?这样我就不需要手动转义 + 量词等。据我所知,数据注释中的 RegularExpressionAttribute 会执行正确的翻译。我能以某种方式重用它吗?

最佳答案

Escape() 是你的 friend :

string escapedInput = Regex.Escape(input);

例如,将 "a+b" 转换为 "a\+b"

关于javascript - 为 javascript 转义 .NET 正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9162143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com