Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all JavaScript regular expressions work in .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,

Differences between C# and JavaScript Regular Expressions? https://www.codeproject.com/Questions/626385/Regex-pattern-for-csharp-and-js

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

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

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

like image 425
Asad Ullah Avatar asked Oct 25 '25 12:10

Asad Ullah


1 Answers

The .NET framework includes the flag RegexOptions.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.


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.

like image 173
Dean Taylor Avatar answered Oct 28 '25 03:10

Dean Taylor