【发布时间】:2018-02-12 00:19:25
【问题描述】:
我正在使用
\[(.*?)\]|Response code (?P<code>\d+)
搜索这些字段:
[2018-01-20 05:19:54.812] INFO com.mulesoft.ch.monitoring.MonitoringCoreExtension [qtp689806602-32]: Monitoring enabled: true
[2018-01-20 05:19:54.813] INFO com.mulesoft.ch.monitoring.MonitoringCoreExtension [qtp689806602-32]: Registering ping flow injector...
[2018-01-20 05:19:54.833] INFO com.mulesoft.ch.queue.boot.PersistentQueueCoreExtension [qtp689806602-32]: The PersistentQueueManager is NOT configured. The normal VM queue manager will be used.
[2018-01-20 05:19:54.841] INFO org.mule.lifecycle.AbstractLifecycleManager [qtp689806602-32]: Initialising RegistryBroker
[2018-01-20 05:19:54.872] INFO
[2018-01-24 02:14:30.153] INFO org.mule.routing.SynchronousUntilSuccessfulProcessingStrategy [[swt-fastsalescomp-anaplan-schedules].ScatterGatherWorkManager.24]: Exception thrown inside until-successful org.mule.module.http.internal.request.ResponseValidatorException: Response code 503 mapped as failure.
但我只希望它匹配日期,而不是括号之间的其他内容以及分配一个命名组“代码”(该部分工作)。我尝试了几种变体,包括
\[(\d*?)\]
\[(\W*?)\]
\[^(\.*?){23}$\]
但我似乎无法让它找到符合这些标准的任何东西。
奖金: 一旦解决了其余问题,我也许可以解决这个问题,但是我不妨在这里问一下。如何使用日期和代码作为键值对更新字典?
【问题讨论】:
-
只有日期,不是时间?
-
@WiktorStribiżew 您可以为正则表达式的第一部分添加
^,以强制它从时间戳的行首开始!!!否则像往常一样好;-)'
标签: regex python-3.x regex-group