User defined language - recognize date and time stamp
-
Hi there,
I try to highlight the date and time stamp in a txt-file by applying UDL, e.g.:
2020-03-31 09:19:44
Unfortunately, it does not work how I want it. I can highlight all numbers, but
in my case I only want to highlight date and time stamp.Does anyone has an idea?
Thank you and best regards!
-
@Ninon_1977 said in User defined language - recognize date and time stamp:
2020-03-31 09:19:44
Maybe by defining
"2020-"
and"09:"
as keywords with checked prefix mode? -
@Ekopalypse said in User defined language - recognize date and time stamp:
@Ninon_1977 said in User defined language - recognize date and time stamp:
2020-03-31 09:19:44
Maybe by defining
"2020-"
and"09:"
as keywords with checked prefix mode?Interesting idea… though I would assume, despite the OP’s lack of information, that it’s possible to have other years (if the txt file goes back more than a few months), and highly probable that it will have hours other than
09
. :-)If this were something I were trying to solve, I’d use your
EnhanceUDLLexer.py
in this linked post, and define a regex similar to\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
– though the OP may have to adjust that regex, depending on whether or not smaller numbers are always zero-prefixed, or only sometimes zero-prefixed (I would hope the former, which would match my regex…) -
@PeterJones
Of course, I simply assumed that the extension of years and hours could be derived from my example :-D
But of course I understand what you mean. :-) -
Hi :-)
I guess "EnhanceUDLLexer.py " could help me, but unfortunately I am not sure how to get it running…
I downloaded the file and renamed it to “EnhanceUDLLexer.py” - I changed this part:self.lexer_name = ‘dummy_Log’
But how can I use it now?
Thank you! -
first you have to install PythonScript plugin from PluginAdmin.
Then click Plugins->PythonScript->New Script
give it a meaningful name and copy the content into the newly created document.Then follow the instructions in the script.
Change the lexername and the regexes in the configuration area.
Lexername must be exactly the same as shown in the language menu
and use the regex from @PeterJonesSomething like this
regexes[(0, (79, 175, 239))] = (r'\d{4}-\d{2}-\d{2} \d{2}:', 0)
all other regexes from the example can be commented.
(79, 175, 239) <-- this is the rgb color
Execute the script via Plugins->Python Script->Scripts->YOUR_SCRIPT
(needs to be done once per npp start only)