我有字符串正则表达式
“product_default_shipping_cost:\['(.*)'”
和字符串
"product_sale_price:['19.99'], product_default_shipping_cost:['1.99'], product_type:['Newegg']"
我只想得到 1.99
。
我的代码:
Pattern pattern = Pattern.compile(regex_string);
Matcher m = pattern.matcher(html);
while (m.find()) {
for (int i = 1; i <= groupCount; i++) {
Log.w(TAG,m.group(i));
}
}
但我有 1.99'], product_type:['Newegg']
奇怪的是,它的正则表达式在 python 和 SWIFT 中完美运行,但在 java 中却不行。我不能改变这个规则。可能是什么问题以及如何解决?
P.S 我真的不能改变这个规则,它需要动态
最佳答案
尝试将其更改为:
product_default_shipping_cost:\['(.*?)'
.*?
是惰性的,只会尝试匹配第一个 '
关于java - 正则表达式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33309508/