Pattern p = Pattern.compile("(\\d+)([¥$])$");
String str = "8899¥";
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println("货币金额: " + m.group(1));
System.out.println("货币种类: " + m.group(2));
Pattern p = Pattern.compile("(\\d+)([¥$])");
String str = "8899¥";
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println("货币金额: " + m.group(1));
System.out.println("货币种类: " + m.group(2));
以上两种的结果都是样
货币金额: 8899
货币种类: ¥
====================================
Pattern p = Pattern.compile("(\\d+)([¥$])$");
String str = "8899$";
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println("货币金额: " + m.group(1));
System.out.println("货币种类: " + m.group(2));
Pattern p = Pattern.compile("(\\d+)([¥$])");
String str = "8899$";
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println("货币金额: " + m.group(1));
System.out.println("货币种类: " + m.group(2));
以上两种的结果都是样
货币金额: 8899
货币种类: $
====================================
请问,正则(\\d+)([¥$])后面加$和不加$的区别?为什么结果是一样?
|