美文网首页
正则表达式

正则表达式

作者: SHAN某人 | 来源:发表于2021-02-04 21:41 被阅读0次

    分组匹配

     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
    

    相关文章

      网友评论

          本文标题:正则表达式

          本文链接:https://www.haomeiwen.com/subject/fnsitltx.html