last day (15 days later) » 

2:16 PM
2
A: How to match multiline log entries with and without keywords (regex)

Alex Voskresenskiy string text = fctb.Text; string strRegex = @"(\*\*\* (.*?)(?=\*\*\* |\z))"; // ANSWER #1 //string strRegex = @"(\*\*\* [^\*]+AGPRSKeysAssocEnum.*?)(?=\*\*\*|\z)"; // ANSWER #2 Regex myRegex = new Regex(strRegex, RegexOptions.Singleline); MatchCollection m = myRegex.Matc...

 
It's not that simple.. First regex doesn't matching all 4 entries (because there is no last ***) Can be checked here regexlib.com/RETester.aspx Only 2 entries are catched
 
last regex maching count = 1 but 3 entries are inside toogether
 
@oobe you need to pick Group[1]
 
sorry.. you are right.. but I've got 4 entries but only 2 are found.. and 6 found in 12 (because it taking last *** of another entries).. so I've got entries no 1,3,5 and so on...
I think those last *** should be used with Lookahead mode.. @"((.?))(?=*)" This is better but does'n matching last entry.
So should be some pattern - line starting from *** and every next lines that doesn't start with ***
 
2:16 PM
@oobe Sorry, i didn't got your question right, see my edit for solution. Yep, it must use lookahead and lookbehind
 
It isn't working.. I'm trying to fix it but what with geting all entries? I changed a little your pattern to this: @"((.?))(?=*)" but this doesn't catch last entry because there in no *** on the end..
maybe something using this stackoverflow.com/questions/10383356/… ? but modified into line starting from *** and every next line that doesn't start from ***
 
@oobe It's done with this regex : (?<=***(.*?)(?=***))
 
that pattern doesn't match last entry strRegex = @"(?<=***(.*?)(?=***))";
 
@oobe forgot endof string, here it is: (?<=***(.*?)(?=***|\z))
 
I found this solution with |z 10 minutes after you :/ Last thing than: strRegex = @"(***(.*?(?<=AGPRSKeysAssocEnum)(?<=AGPRSKeysAssocEnum).*?)(?=***))"; matching one entry and every group has string with entry 1 and 2 together (should be only 2nd entry)
 
2:16 PM
@oobe Edited my answer, now it must work great
 
Almoust done :D but now are 2 matchings. Second match is incorrect. Remember that I need also with first *** chars.. so I always also editing begining of your pattern from (?<=*** to (***
 
@oobe I give up... None of methods i try worked with keyword matching, so i recommend you to split your logs into entries and then (hehe, you can do this in parallel) run a regex like .*?<Keyword>.*|\z for each entry
 
That' s too bad :(, because I need it for syntax highlighting (on live). Don't give up pls :D I'll be checking for your answers ;) BTW maaaaaaany thanks for trying.
 
@oobe that's not problem oftrying, the problem is that regular expressions are not gods and kings. The biggest problem i ran into is that we need to match symbols eager inside our lookarounds and so we get matches of 2+ entries in one... As for syntax highlighting, i find regex absolutelly unreadable whether you use resharper or stuff and (IMHO) c# code is much more clean and clear :)
 
I know that but I'm not giving up. This one @"(AGPRSKeysAssocEnum(.*?))(***|\z)" isn't correct because I don't geting first part of entry log but I'm thinking how to get this part of entry.
I finally did it! :D I've changed your answer and I'll accept it as soon as "peer reviewed" dissapear. Thank you verry much @Alex Voskresenskiy
 
2:16 PM
@oobe Great Job! I really gave too much sense to .* :) The only thing i remind you is to put ?= before ***|\z
 
Why? I don't need this. I want whole lines also with those *** at the begining. Thank's again!
 
@oobe Because you don't need to capture ending *'s, or you'll have a problem of matching 1,3,5 and not 2,4 etc. :) You're welcome!
 

  last day (15 days later) »