Parse a specific string start and stop position?
So here is an example of part of our error message string below and what i want to do is parse a field specifically that has in it the value "app.ERROR" as the value, this string varies as it can be api.ERROR, or app.WARNING etc.. the only thing i know for sure in our log file is where the field STARTS in the file, meaning it will always start at position 23 and goes up to the colon (:). But i cannot find a good example of doing this. I would imagine REGEX is used here but just cannot find exactly what i need here.
If anyone has a good way of doing this i would VERY much appreciate it :)
[2017-09-12 01:42:41] app.ERROR: exception |
-
Hi Bill,
I was able to put together the following regex to parse the message that you specified above.
The regex statement below will count out 22 non-carriage return characters from the start of the string and then begin parsing the start of the "msg" field. This field will match any non-carriage return characters from the 23rd character to the colon, and will extract this text as a named value called "msg". If you want to extract the text after the colon into its own named field then that can be accomplished by putting in another similar named field, I can help with that as well if you'd like.I hope this helps, please let me know if you have any questions.
^[^\r]{22}(?<msg>[^\r]*?):
Please sign in to leave a comment.
Comments
2 comments