Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
过滤掉Java中的价格或成本_Java_Regex - Fatal编程技术网

过滤掉Java中的价格或成本

过滤掉Java中的价格或成本,java,regex,Java,Regex,我有((?:[0-9]{1,3}[\,]?)*[\,]?[0-9]+)来过滤java上字符串中的价格,因此我将它们放在如下位置: public static final String new_price = "((?:[0-9]{1,3}[\\.,]?)*[\\.,]?[0-9]+)"; final Pattern p = Pattern.compile(new_price, 0); final Matcher m = p.matcher(label); if (m.match

我有
((?:[0-9]{1,3}[\,]?)*[\,]?[0-9]+)
来过滤java上字符串中的价格,因此我将它们放在如下位置:

public static final String new_price = "((?:[0-9]{1,3}[\\.,]?)*[\\.,]?[0-9]+)";

final Pattern p = Pattern.compile(new_price, 0);
    final Matcher m = p.matcher(label);
    if (m.matches()) {
        Log.d(TAG, "found! good start");
        if (m.groupCount() == 1) {
            Log.d(TAG, "start match price" + " : " + m.group(0));
        }
        if (m.groupCount() == 2) {
            Log.d(TAG, "start match price" + " : " + m.group(1));
        }
    }

我正在处理样本,但它在运行时从未找到匹配项。有什么想法吗?

不要使用
matches()
你应该运行
m.find()
来搜索下一个匹配项(这应该在
while
循环中完成!):

输出

found! good start
start match price : 500.00
found! good start
start match price : 522.30

我们应该猜猜你的输入是什么样子的,你到底想匹配什么?或者你会慷慨地与我们分享这些小细节吗?字符串示例:
$500.00-$522.30
我希望得到500.00和522.30,所以我不应该从.matches()开始?@HeskeyoKam我感觉你把
Matcher.matches()
字符串.matches()
混淆了,下面是一个例子,我终于找到了找到匹配项的正确方法。这里的代码仅供参考。
found! good start
start match price : 500.00
found! good start
start match price : 522.30