【发布时间】:2020-07-30 17:04:55
【问题描述】:
下面的正则表达式提取整数,但有一种情况失败。
示例字符串:
Monday,City=Nice,total\ avg\ shops=350,avg\ shops=20 month=jan
Monday,City=Nice total\ avg\ shops=23 avg\ shops=10 month=Feb
Monday,City=Nice total\,avg\ shops=30 avg\ shops=50 month=Feb
Monday total\,avg\,shops=30 avg\ shops=50,City=Nice month=Feb
Region,Network=myTelco total\ avg\ shops=30.0 avg\ shops=20color=Pink 1590424200000000000
我的正则表达式:
(?:(?<![^,])|=\w+\s+)avg\\ shops\s*=([0-9.]+)
示例代码:
val matcherInt = Pattern.compile(s"(?:(?<![^,\\s])|=\\w+\\s+)$targetz\\s*=([0-9.]+)").matcher(valueInt)
if (matcherInt.find()) {
println( matcherInt.group(1))
} else
println("Nothing match")
【问题讨论】:
-
请用当前输出和预期输出指定失败案例
-
@Anshuman 在演示链接中很清楚,
Region,Network=myTelco total\ avg\ shops=30.0 avg\ shops=20color=Pink 1590424200000000000没有匹配。