I am writing a regex for this test string,
2021-11-25 17:04:48,015 INFO [wso2/gateway/src/gateway/utils] - [BlockingConditionRetrievalTask] [-] Blocking condition retrieval successful. Stopping the timer task ...
here is the regex i got so far,
^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])* (?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d),\d{3} {1,2}(?<loglevel>[DEBUG\ INFO\ ERROR\ WARN][A-Z]*)\s
how to write the regex for the [wso2/gateway/src/gateway/utils] which is an endpoint and the [BlockingConditionRetrievalTask]
Regards.
CodePudding user response:
You can use
^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d \s (?<loglevel>[A-Z] )\s \[(?<logendpoint>[^\]\[]*)]\s \S \s \[(?<logtask>[^\]\[]*)]
See the regex demo. Details:
^- start of string\d{4}-\d{2}-\d{2}- date-like pattern\s- a whitespace\d{2}:\d{2}:\d{2},\d- time-like pattern\s- one or more whitespaces(?<loglevel>[A-Z] )- Group "loglevel": one or more uppercase letters\s- one or more whitespaces\[- a[char(?<logendpoint>[^\]\[]*)- Group "logendpoint": any zero or more chars other than]and[]\s \S \s \[-], one or more non-whitespaces enclosed with one or more whitespaces, and a[char(?<logtask>[^\]\[]*)- Group "logtask": any zero or more chars other than]and[]- a]char.
