Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:49+00:00 2026-06-12T05:26:49+00:00

I want to write a custom language for access logs in Notepad++. The Problem

  • 0

I want to write a custom language for access logs in Notepad++.

The Problem is that numbers (here: HTTP status codes) won’t be highlighted like real keywords (i.e. GET). Notepad++ only provides a highlight color for numbers in general.

How do I handle numbers like text?

Sample log file

192.23.0.9 - - [10/Sep/2012:13:46:42 +0200] "GET /js/jquery-ui.custom.min.js HTTP/1.1" 200 206731
192.23.0.9 - - [10/Sep/2012:13:46:43 +0200] "GET /js/onmediaquery.min.js HTTP/1.1" 200 1229
192.23.0.9 - - [10/Sep/2012:13:46:43 +0200] "GET /en/contact HTTP/1.1" 200 12836
192.23.0.9 - - [10/Sep/2012:13:46:44 +0200] "GET /en/imprint HTTP/1.1" 200 17380
192.23.0.9 - - [10/Sep/2012:13:46:46 +0200] "GET /en/nothere HTTP/1.1" 404 2785

Sample custom languages
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files

I also tried editing and importing a predefined language like this:
http://notepad-plus.sourceforge.net/commun/userDefinedLang/Log4Net.xml

I thought the custom language should look like this:

<KeywordLists>
[...]
    <Keywords name="Words1">404 501</Keywords>
    <Keywords name="Words2">301 303</Keywords>
    <Keywords name="Words3">200</Keywords>
</KeywordLists>

<Styles>
    <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" colorStyle="0" fontName="Courier New" fontStyle="0"/>
    [...]
    <WordsStyle name="KEYWORD1" styleID="5" fgColor="FF0000" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="0"/>
    <WordsStyle name="KEYWORD2" styleID="6" fgColor="0000FF" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="1"/>
    <WordsStyle name="KEYWORD3" styleID="7" fgColor="00FF00" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="0"/>
    [...]

    // This line causes number highlighting. Deletion doesn't work either.
    <WordsStyle name="NUMBER" styleID="4" fgColor="0F7F00" bgColor="FFFFFF" fontName="" fontStyle="0"/>
</Styles>

Unfortunately numbers will be colored in the same color.

I’d like to color them like this:
Sample highlighting of numbers in the access log

etc.

Any suggestions? How to handle the numbers like keywords?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:26:51+00:00Added an answer on June 12, 2026 at 5:26 am

    It isn’t possible to highlight numbers as keywords as the built-in lexers (parsers/language definitions) use a numeric as a token meaning that the only way to differentiate between a numeric and your keyword would be to parse the whole numeric block and then compare to the keyword list, in which case it becomes required to also parse the delimiters around the numeric block to ensure that .200. doesn’t highlight as 200. This is why your numbers all highlighted as the same color; namely the ‘number’ color.

    While this could be done using a custom lexer using either fixed position tokens or regex matching you’ll find the user defined languages (the last I heard) do not have this capability.

    As your request is actually a fairly simple, from what I understand, being as general as possible ( as requested in your comment )…

    Highlight space delimited numeric values contained in a given set.
    
        [[:space:]](200|301|404)[[:space:]]
    

    We can use the ‘Mark’ feature of the ‘Find’ dialog with that regex but then everything is marked the same color like with your failed experiment.

    Perhaps what would be simple and suit your needs would be to use a npp pythonscript and the Mark Style settings in the Style Configurator to get the desired result?

    something like this crude macro style:

    from Npp import *
    
    def found(line, m):
        global first
        pos = editor.positionFromLine(line)
        if first:
            editor.setSelection(pos + m.end(), pos + m.start())
            first = False
        else:
            editor.addSelection(pos + m.end(), pos + m.start())
    
    
    editor.setMultipleSelection(True)
    lines = editor.getUserLineSelection()
    
    # Use space padded search since MARKALLEXT2 will act just
    # like the internal lexer if only the numeric is selected
    # when it is called.
    
    first = True
    editor.pysearch( " 200 ", found, 0, lines[0], lines[1])
    notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT1)
    
    first = True
    editor.pysearch( " 301 ", found, 0, lines[0], lines[1])
    notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT2)
    
    first = True
    editor.pysearch( " 404 ", found, 0, lines[0], lines[1])
    notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT3)
    

    Which, to use, just use the plugin manager to install Python Script, go to the plugin menu and select New Script then paste, save, select the tab for the doc you want to parse, and execute the script (once again from the plugin menu).

    Obviously you could use all 5 Mark styles for different terms, you could assign to a shortcut, and you could get more into the ‘scripting’ -vs- ‘macro’ style of nppPython and make a full blown script to parse whatever you want… shoot having a script trigger whenever you select a particular lexer style is doable too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a custom alarm for a Mac that awakes the mac
I want to write a custom selector to select all fields that are returned
I want to write a compiler for a custom markup language, I want to
I want to write a custom class that behaves like dict - so, I
I want to write a custom validator for MVC.NET framework that checks if entered
I want to write a custom view engine that returns custom text (like coma
I want to write a custom module that adjusts which columns are visible when
I want to write a custom validator which doesn't do anything before the user
I have a large data set and I want to write a custom merge
I want to write a program in Prolog that confirms if a b-tree of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.