Optional expressions at end of string?
Given the following message:
17:11:31,470 WARN FooController:118 - Invalid request: partnerId=blarg*t&f=d%2Ca&d=x&s=blarg&z=320x50%2C300x50 : Dalvik/1.6.0
(Linux; U; Android 4.1.2; SGH-T999 Build/JZO54K)
Using the following pattern I'm able to get level, class, and message just fine but I want to do is *optionally* add the capture for user-agent (Davlik/1.6.0 to end of string) at the end of the expression. It may or may not be present.
Here's my attempt:
"\d{2}:\d{2}:\d{2},\d+ (?<level>[A-Z]+) (?<class>[A-Za-z]+):\d+ - (?<message>.*?)(\s:\s(?<user\_agent>.*))?$"
Trying a non-greedy match on message then looking, optionally, for the presence of " : "
But Sumo fails w/:
The following errors were reported when executing your search:
unknown error (2)
It doesn't seem to care much for the optional expression there at the tail end.
Is this madness?
-
Cory,
For the option expression in the parse regex you need to supply this within a non-capturing group, for example (?:string) So just a minor update to your expression should hopefully get your results and remove the error your seeing.
| parse regex "\d{2}:\d{2}:\d{2},\d+(?<level>[A-Z]+)(?<class>[A-Za-z]+):\d+ - (?<message>.*?)(?:\s:\s(?<user\_agent>.*))?$"
Please sign in to leave a comment.
Comments
2 comments