I want to use RE to parse a log file and return the orderid if it exists. For example:
Here is a sample log
2012-07-19 12:05:04,288 [22] INFO AddQueueCommand [(null)] - Status set to Subscribed
2012-07-19 12:05:04,288 [23] INFO FooBarProviderFactory [(null)] - Missing Function : OrderId:102602 : Method:AddOrderToId : application:11
2012-07-19 12:05:04,288 [22] INFO AddQueueCommand [(null)] - Status set to Pending
2012-07-19 12:05:04,288 [23] INFO AddSubscription [(null)] - Subscription Added. OrderId:102603 : application:15
2012-07-19 12:05:04,288 [22] INFO AddQueueCommand [(null)] - Status set to Subscribed
What I want to do is use a regular expression so I can parse the components of the log message. But when an "OrderId" exists, I want to be able to parse the orderid #.
Here is what I have so far:
^
(?<before>.*)
(?<order>((?<=OrderId\:\s*)\d*))
(?<after>.*)
$
which works great for parsing the orderids for lines that have them, but it fails when the line doesn't have them. I tried adding the "?" zero or one to the order row which then parses all the rows, but never parses the actual orderid. They are always null.
Hope someone can see what I am doing wrong. Thanks!
(I want it to parse every line because I am going to parse multiple ids values from each row and they may or may not exist. I want it to return the value if what I am searching for exists or null/empty if it doesn't exist. It needs to return something for every row. This will be plugged into LogParser so we can query or logs for specific orders or other variables)