Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

javascript - 正则表达式C#不能与javascript保持一致(Regex C# not working consistent with javascript)

I have an issue about regex This is my string str = 'tat" and I'm using regex for(我有一个关于正则表达式的问题,这是我的string str = 'tat" ,我正在使用正则表达式)

javascript:(javascript:) str = str.replace(/[^\w\\-]+/g, ''); => result: tt c#:(C#:) str = (new Regex(@"[^\w\\-]+")).Replace(str, ""); => result: tat I want to make result of C# like javascript, Please help me.(我想使C#的结果像javascript,请帮助我。) Thanks so much(非常感谢)   ask by Minh Hai Vu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The default .Net implementation of Regex is slightly different from the Javascript implementation.(Regex的默认.Net实现与Javascript实现略有不同。)

Differences are described on on the Microsoft website .(差异在Microsoft网站上有描述。) To use Javascript/ECMAscript rules in .Net:(在.Net中使用Javascript / ECMAscript规则:) str = Regex.Replace(str, @"[^w\-]+", "", RegexOptions.ECMAScript);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...