Community
    • Login

    How to highlight numbers WITHIN words

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 1.4k 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.
    • Sean VoltaireS
      Sean Voltaire
      last edited by Sean Voltaire

      It seems like such a simple feature I feel like I must be doing something wrong.

      I have already tried toggling the setting “Match whole word only” in Preferences>Highlighting>Smart Highlighting. It seems to have no effect for this issue.

      I’ve also tried getting it done with UDL. As you can see in the screenshot, I can get numbers to highlight in the middle of ‘words’(really just characters surrounded by whitespace) only if they are surrounded by operators. For example I can add the character ' to the Operators 1 field and it will highlight the rest of those instances of “3479”.

      Furthermore I gather that there is no ((SPACE)) keyword that I can use in UDL like there is for ((EOL))? That would help with my UDL greatly.

      2022-08-05 10_57_38-C__DevTools_Omega_Build_Source_Omega_Logs_OmegaVR_168861635.log - Notepad++.png

      EkopalypseE PeterJonesP 2 Replies Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @Sean Voltaire
        last edited by

        @Sean-Voltaire

        see here https://ivan-radic.github.io/udl-documentation/numbers/ if this can help.

        8e889322-e38c-4cc1-9562-c1c169a2fdf2-image.png

        1 Reply Last reply Reply Quote 2
        • PeterJonesP
          PeterJones @Sean Voltaire
          last edited by

          @Sean-Voltaire said in How to highlight numbers WITHIN words:

          I have already tried toggling the setting “Match whole words only”

          Preferences>Highlighting>Smart Highlighting only affects what is shown when you manually select a piece of text: if you select 314159 here, then it will look like:

          Any Whole Words Only
          0110005c-2c89-4945-afbf-cba3a4e8c751-image.png 5a9ee64c-1b2a-4aa4-aad4-322950bf95aa-image.png

          But that will only show you exactly the digits that are currently selected – so it finds the digits of pi, but not the digits of e, since the digits of pi are the ones I had selected.

          That option does not affect UDLs.

          I wasn’t sure if that was tried as a way to change the behavior of the UDL, or if that “match whole word only” was meant to affect something else other than manually selecting text and having it highlight all other text that matches the selection.

          If you couldn’t think of other ways to manually select/mark digits: use the Search > Mark (Ctrl+M) and use a regular expression to manually mark all strings of digits.

          04917b6d-291b-4a74-9aa7-7dd2f9395ae8-image.png

          But given your focus on UDL in the rest of your question, I wonder if you are really just trying to change UDL behavior. You cannot do that with any of the options in the Preferences dialog; UDL is controlled via the UDL dialog/panel and that’s it.

          As far as UDL syntax goes: no, there is no ((SPACE)). ((EOL)) is the only fancy escape… well, except for enclosing a term in quotes: "key word" will match key word but not key other word

          cf28a316-8c9f-4b96-9138-77011b395f0d-image.png

          The quote-around-spaces works for keywords and folding-in-code-2, but in my experiments today, I couldn’t get it to work in folding-in-code-1 or comment-line or operators or delimiters. So that might work for your ((SPACE)) desire, in certain circumstances.

          If you’re really looking to highlight extra numbers that are in weird situations and would like to be able to use a regex but otherwise treat it as a UDL, you can use @Ekopalypse’s Enhance Any Lexer. For example, if I have a UDL called “voltaire” which uses an aqua-like color similar to what you have for its “number style”, and in Enhance Any Lexer, set

          [voltaire]
          0xFFFF00 = (?<=[\l\u_])\d+|\d+(?=[\l\u_])
          

          which will set digits to bright cyan if they have upper or lowercase or underscore to the left or right; otherwise, if the UDL thinks of it as a “word” of numbers (spaces or operators to either side), then the UDL will highlight them with the aqua.

          adc84e21-736b-4a56-b90d-d31c8dc9d19d-image.png

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