Detecting filename via regex, trouble with auto-detect


Author
Message
strat68
strat68
New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)
Group: Forum Members
Posts: 5, Visits: 41
Hi, this is a question regarding regex in detecting a file name pattern (not parsing of the contents).

In the app I work with we have logfiles with a simple format filename.log, then we have rollovers based on policy (size/age) that look like:  filename.log.2020-12-19.1 (last digit increments: 2,3,...999).  Obviously, the other digits are YYYY-MM-DD.

Using the website regex101 dot com, I created and tested my regex for the above rollover and it works correctly:
^[a-z].*\.log\.[0-9]{4}\-[0-9]{2}\-[0-9]{2}\.[0-9]{1,3}$

I don't believe ^ and $ are needed for a filename (maybe if it contains spaces??) but I tried with and without, and same result.  Auto-detect does not pickup the pattern in my parser mappings, and it goes to basic parser.  I know the workaround of going to "Parse With" but just curious, is it some kind of versioning with Regex?  Or does LVP use a subset of regex? 

Also, my parser args for the file content are, of course, the same for current log or the rollover. Would I be better off keeping one mapping and using a logical OR.  e.g  ( patternA | patternB)?

Feedback appreciated, thanks!
Edited 4 Years Ago by strat68
LogViewPlus Support
LogViewPlus Support
Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)
Group: Moderators
Posts: 1.1K, Visits: 3.7K
Hi Strat,

LogViewPlus uses the standard Microsoft .Net regex libraries.  I would not anticipate any problems with the parsing library itself, or significant deviations from the standard.

I would suggest trying two things.  First, go into Settings -> Parser Mappings -> Parser Wizard.  The first page of the Parser Wizard allows you to test a regular expression against a file name.



See if you can modify your regular expression here to make it work.  Sometimes speeding up the test cycle helps.  Don'f forget to check the 'Is Regex' checkbox.  

If that fails, you may want to try a less restrictive matching pattern.  For example *.log.*.*.*..  If you want to stick with a regex, you could try .*\.log.*\..*\..*\..*

Hope that helps,

Toby


strat68
strat68
New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)New Member (32 reputation)
Group: Forum Members
Posts: 5, Visits: 41
Thanks Toby!  Note I've edited the OP, the dates were supposed to have hyphens MM-DD-YYYY.1 (not dots).  So your test may have worked if I had only given you accurate information!

I am pretty sure I pasted direct from regex101 tester right to LVP, not sure why I had a problem (the typos occurred making the OP).  I checked your .net links, and they do support the quantifier, so it's all good there and I was able to proceed on my regex with confidence :-) !

I came up with this:  [a-z]{1,20}[_]{0,1}[a-z]{1,20}\.log($|\.[0-9]{2}\-[0-9]{2}\-[0-9]{4}\.[0-9]{1,3}$)

Which matches:  filename.log, file_name.log, and the previous two with rollover extensions of .MM-DD-YYYY.1  (up to .999).

The limitations of 1-20 before and after the (possible) underscore, are mine based on observation. We're not near that at the moment.  You can see, I love this quantifier thingy.

Edited 4 Years Ago by strat68
LogViewPlus Support
LogViewPlus Support
Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)
Group: Moderators
Posts: 1.1K, Visits: 3.7K
That is one impressive regex.  :-)  Glad to hear you got it working - thanks for letting me know!

Toby
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Login

Explore
Messages
Mentions
Search