You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整JavaScript正则将Mule日志捕获分组拆为6组

正则调整方案

调整逻辑

利用日志中第5分组为固定36位UUID(8位-4位-4位-4位-12位十六进制+分隔符结构)的特征,将原有合并的第4分组拆分为两部分:

  • 第4分组匹配到event:后缀为止
  • 新增第5分组精准匹配UUID
  • 剩余日志内容作为第6分组

完整实现代码

var myString = "[2021-11-15 23:43:41.867] INFO    [Mule-util]nz.co.ha.mule.common.logging.CustomMessageLogger [[MuleRuntime].uber.02: [sample-logging-app].sample-logging-appFlow.CPU_LITE @4ffd3e60]: event:dd3aa370-466d-11ec-83a1-0ab55c0b0cf4 ||transactionID=null|txnState=start|apiDomain=system|apiLayer=system|customMessage=Im%20here%20at%202021-11-15%2023:43:41.866|direction=incoming|messageName=sample-loggin-app|messageType=sample-loggin-app|name=main|payloadIn=false||";
// 调整后的正则表达式
var myRegexpStr = /^(\[[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{3}\])\s([A-Z]*)\s*([\[\]a-zA-Z0-9\.\-:]*)\s([0-9a-zA-Z@\[\].\s\-_:]*?:\sevent:)([0-9a-fA-F\-]{36})\s([\s\S]+)/g;
var myRegexp = new RegExp(myRegexpStr);
var match = myRegexp.exec(myString);
// 分组输出验证
console.log(match[1]); // [2021-11-15 23:43:41.867]
console.log(match[2]); // INFO
console.log(match[3]); // [Mule-util]nz.co.ha.mule.common.logging.CustomMessageLogger
console.log(match[4]); // [[MuleRuntime].uber.02: [sample-logging-app].sample-logging-appFlow.CPU_LITE @4ffd3e60]: event:
console.log(match[5]); // dd3aa370-466d-11ec-83a1-0ab55c0b0cf4
console.log(match[6]); // ||transactionID=null|txnState=start|apiDomain=system|apiLayer=system|customMessage=Im%20here%20at%202021-11-15%2023:43:41.866|direction=incoming|messageName=sample-loggin-app|messageType=sample-loggin-app|name=main|payloadIn=false||

内容的提问来源于stack exchange,提问作者Pathfinder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 06:15:06