正则表达式删除所有(非数字 OR 句点) [英] Regex to remove all (non numeric OR period)
本文介绍了正则表达式删除所有(非数字 OR 句点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将joe ($3,004.50)"之类的文本过滤到 3004.50,但我在正则表达式方面很糟糕,找不到合适的解决方案.所以只有数字和句点应该保留 - 其他一切都被过滤了.我使用 C# 和 VS.net 2008 框架 3.5
I need for text like "joe ($3,004.50)" to be filtered down to 3004.50 but am terrible at regex and can't find a suitable solution. So only numbers and periods should stay - everything else filtered. I use C# and VS.net 2008 framework 3.5
推荐答案
应该这样做:
string s = "joe ($3,004.50)";
s = Regex.Replace(s, "[^0-9.]", "");
这篇关于正则表达式删除所有(非数字 OR 句点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文