需要一个正则表达式来删除除数字以外的所有内容 [英] Need a regex to remove everything except numbers
本文介绍了需要一个正则表达式来删除除数字以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要除 [^0-9\n] 之外的其他东西,我想要一个正则表达式(但不知道如何制作),它可以以这样的数字模式捕获任何内容,0000000000"或000-000-0000" 或基本上任何在前面或中间带有空格和/或特殊字符的数字.
I need something besides [^0-9\n], I want a regex(but dont know how to make one), that captures anything in a pattern of numbers like this, "0000000000" or "000-000-0000" or basically any numbers that exist with spaces and or special characters right before or in between.
所以任何数字,即使像这些 (626*) 34a2-4387) 也应该转换为 6263424387
so any number, even like these (626*) 34a2- 4387) should convert to 6263424387
这怎么可能完成?我觉得太难了?
How can this be accomoplished? Im thinking its too hard?
推荐答案
您可以使用以下方法搜索所有非数字:
You can search for all non-digits using:
\D+
或
[^0-9]+
并替换为空字符串.
这篇关于需要一个正则表达式来删除除数字以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文