简体   繁体   中英

C# Regex remove everything except \d+, one, nine and decimal point

How can i do something like this.

new Regex("([^\d+]|[^one]|[^nine]|[^,])").Replace("Fi10An,fONEy,Onineo", "");

I would get this:

10,one,nine

But i would get a empty string with my wrong regex above.

Thank you in Advance!

Try doing the opposite: match what you need and then take it from the string. For example:

Regex.Matches("Fi10An,fONEy,Onineo", @"(\d+|one|nine|,)", RegexOptions.IgnoreCase)

And then combine the matches into one string. This would be the easiest and the clearest solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM