How to modify regular expressions so that it extracts same fields of both fields?

百般思念 提交于 2021-01-07 01:33:00

问题


When looking for some logs in one file I got two types of logs (one with white spaces and one without). I would now like to extract doSomething and doAnotherThing out of these logs with one regular expression.

Logfile 1: "taskType":"doSomething"

Logfile 2: "taskType" : "doAnotherThing"

I coded this regular expression: taskType.....(?<taskType1>\w+)

It works good for Logfile 1 but not for Logfile 2, because it cuts the first two characters of the word. Is there a way to eliminate this issue?

Thanks!


回答1:


"taskType"\s?:\s?"(doSomething|doAnotherThing)" works for me, try it here https://regex101.com/r/Mx1RtT/1



来源:https://stackoverflow.com/questions/64912713/how-to-modify-regular-expressions-so-that-it-extracts-same-fields-of-both-fields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!