我有以下格式的字符串
Local Tax 02/07 02/14 -0.42
我想将以上内容拆分为三个单独的刺痛,例如
Local Tax
02/07 02/14
-0.42
我写了以下代码片段
package com.demo;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DemoClass {
/**
* @param args
*/
public static void main(String[] args) {
String s ="Sales Tax 08/07 09/06 0.42";
//String s1 = "Sales Tax 02/07 02/14 -1.02";
Pattern pattern = Pattern.compile("^([a-zA-Z ]*) ([0-9]{2}/[0-9]{2} [0-9]{2}/[0-9]{2}) ([-[0-9]*.[0-9][0-9]|[0-9]*.[0-9][0-9]])");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
System.out.println("String Name::"+s);
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
System.out.println(matcher.group(3));
}
}
}
我得到的输出为
String Name::Sales Tax 08/07 09/06 0.42
Sales Tax
08/07 09/06
0
matcher.group (3)应该返回 0.42,但它显示为 0。请在这方面帮助我。