不应考虑字符串末尾的空格或两个数字之间的空格,但它可以在数字之前或之后,但不能在数字之间. 我编写了一个正则表达式,但根据我的要求,它并不适用于所有条件.
Pattern pattern =Pattern.compile("\\s(?![\\d\\s]*\\d$)");
Matcher matcher=pattern.matcher(input);
int lastIndex=-1;
while(matcher.find()){
lastIndex=matcher.start());
}
我如何使用正则表达式和任何其他方式来实现我的要求,以便在没有While循环的情况下获得最后一个匹配项? 示例
jumnsch@domain.com m 5180-3807-3679-8221 612 3/1/2010
^
hello this card number 4444 5555 6666 7777
^
hello this bob
^