我已经编写了一个正则表达式,可以省略在某些字符(,和#)的第一次出现之后的所有字符。
String number = "(123) (456) (7890)#123";
number = number.replaceAll("[,#](.*)", ""); //This is the 1st regex
然后使用第二个正则表达式仅获取数字(删除空格和其他非数字字符)
number = number.replaceAll("[^0-9]+", ""); //This is the 2nd regex
输出:1234567890
如何将两个正则表达式合并成一个,就像将第一个正则表达式的输出传递到第二个正则表达式中一样。
number.match(\\d+")
- Tushar[,#].*$|[^#,0-9]+
- Wiktor Stribiżew