所有 JavaScript 正则表达式都可以在 .NET 中使用吗? [英] Do all JavaScript regular expressions work in .NET?

查看:26
本文介绍了所有 JavaScript 正则表达式都可以在 .NET 中使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 JavaScript 和 .NET 中使用的正则表达式之间的区别.我已经阅读了几篇关于它的文章,

I am trying to understand the difference between regular expressions that are used in JavaScript and .NET. I have read couple of articles on it,

C# 和 JavaScript 正则表达式之间的区别?https://www.codeproject.com/Questions/626385/Regex-pattern-for-csharp-and-js

我从这两个问题中了解到,.NET 支持一些扩展字符,而 JavaScript 有一些限制.

What i understood from both of these questions is that .NET have support for some extended characters and JavaScript have some limitations.

可以肯定地说,如果正则表达式在 JavaScript 中有效,那么它在 .NET 中肯定也有效吗?

Is it safe to say that if a regular expression works in JavaScript then it will definitely work in .NET?

期望的结果:我想维护一个常用正则列表适用于 JavaScript 和 .NET 的表达式.

Desired result: I want to maintain a list of common regular expressions that work on both JavaScript and .NET.

推荐答案

.NET 框架包含标志 RegexOptions.ECMAScript.

The .NET framework includes the flag RegexOptions.ECMAScript.

ECMAScript 是为了标准化 JavaScript 而创建的,所以你会发现不同的 JavaScript 引擎会有对 ECMAScript 标准及其修订版的不同支持级别.

ECMAScript was created to standardise JavaScript, so you will find that different JavaScript engines will have differing levels of support for the ECMAScript standard and its revisions.

文档包含一些关于 ECMAScript 匹配行为,值得一提.

The documentation contains some specific notes on the differences in ECMAScript Matching Behaviour which would be worth noting.

简而言之;在 C# 中使用 RegexOptions.ECMAScript 标志并开发您的正则表达式 - 然后您应该会发现您的正则表达式可以在 JavaScript 中工作.

So in short; using the RegexOptions.ECMAScript flag in C# and developing your regular expressions - you should then find that your regular expressions then work in JavaScript.

这篇关于所有 JavaScript 正则表达式都可以在 .NET 中使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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