Reputation: 71
I have an issue about regex
This is my string str = 'tât"
and I'm using regex for
javascript:
str = str.replace(/[^\w\\-]+/g, ''); => result: tt
c#:
str = (new Regex(@"[^\w\\-]+")).Replace(str, ""); => result: tât
I want to make result of C# like javascript, Please help me.
Thanks so much
Upvotes: 4
Views: 73
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
Reputation: 41
You could try using a Alphabetic range like that:
str= (new Regex(@"[^A-Za-z0-9]+")).Replace(str, "");
Upvotes: 1