分组匹配
def main(args: Array[String]): Unit = {
val str = "<doc table=\"Target\" action=\"Modify\" time=\"2021-02-04 20:46:10\" partitionId=\"0\" partitionSize=\"6\" partitionKey=\"74514480\" source=\"FunDpShopStockSearch\" srcTimeMillis=\"1612442770000\" preConvertTimeMillis=\"1612442770239\" postGenMsgTimeMillis=\"1612442770275\"> targetId=16260698 cpcTgIdx= cpcTgIdxHash=0 </doc>"
val pattern = Pattern.compile("(\\w+)=\"(\\d+)\"")
val matcher = pattern.matcher(str)
while (matcher.find()){
// 0 是全部
val rest =matcher.group(1)
val rest1 =matcher.group(2)
println(s" ${matcher.group(0)} $rest => $rest1")
}
}
partitionId="0" partitionId => 0
partitionSize="6" partitionSize => 6
partitionKey="74514480" partitionKey => 74514480
srcTimeMillis="1612442770000" srcTimeMillis => 1612442770000
preConvertTimeMillis="1612442770239" preConvertTimeMillis => 1612442770239
postGenMsgTimeMillis="1612442770275" postGenMsgTimeMillis => 1612442770275
网友评论