Minh Hai Vu
Minh Hai Vu

Reputation: 71

Regex C# not working consistent with javascript

I have an issue about regex This is my string str = 'tât" and I'm using regex for

I want to make result of C# like javascript, Please help me.

Thanks so much

Upvotes: 4

Views: 73

Answers (2)

GvS
GvS

Reputation: 52518

The default .Net implementation of Regex is slightly different from the Javascript implementation.

Differences are described on on the Microsoft website.

To use Javascript/ECMAscript rules in .Net:

   str = Regex.Replace(str, @"[^\w\\-]+", "", RegexOptions.ECMAScript);

Upvotes: 5

Flocke
Flocke

Reputation: 41

You could try using a Alphabetic range like that:

str= (new Regex(@"[^A-Za-z0-9]+")).Replace(str, ""); 

Upvotes: 1

Related Questions