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

查看:98
本文介绍了所有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.


推荐答案

The。 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.

该文档包含一些特定的关于

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天全站免登陆