-4

在句子中

-[Multiple space characters] 1GB – 10TB is $0.19/GB

我正在尝试提取1GB, 10TB, %0.19/GB. 我尝试使用正则表达式

("-.*(\\d.*)-(\\d[^ ])\\sis\\s(.+)

在java中,但它不起作用。谁能帮我吗?

4

1 回答 1

1

Try aiming for the values:

String test = "-[Multiple space characters] 1GB – 10TB is $0.19/GB";
Pattern pattern = Pattern.compile("\\$?[\\d\\.]+/?(G|T)B");
Matcher matcher = pattern.matcher(test);
while (matcher.find()) {
    System.out.println(matcher.group());
}

Output:

1GB
10TB
$0.19/GB
于 2013-06-14T13:25:25.147 回答