• Login
Community
  • Login

User defined language - recognize date and time stamp

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 1.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N
    Ninon_1977
    last edited by Apr 6, 2020, 11:04 AM

    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!

    E 1 Reply Last reply Apr 6, 2020, 12:49 PM Reply Quote 0
    • E
      Ekopalypse @Ninon_1977
      last edited by Apr 6, 2020, 12:49 PM

      @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?

      P 1 Reply Last reply Apr 6, 2020, 1:01 PM Reply Quote 1
      • P
        PeterJones @Ekopalypse
        last edited by Apr 6, 2020, 1:01 PM

        @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…)

        1 Reply Last reply Reply Quote 3
        • E
          Ekopalypse
          last edited by Apr 6, 2020, 1:06 PM

          @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. :-)

          1 Reply Last reply Reply Quote 1
          • N
            Ninon_1977
            last edited by Apr 7, 2020, 8:50 PM

            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!

            E 1 Reply Last reply Apr 7, 2020, 9:49 PM Reply Quote 0
            • E
              Ekopalypse @Ninon_1977
              last edited by Ekopalypse Apr 7, 2020, 9:51 PM Apr 7, 2020, 9:49 PM

              @Ninon_1977

              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 @PeterJones

              Something 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)

              1 Reply Last reply Reply Quote 2
              1 out of 6
              • First post
                1/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors