bugGNU nano - Bugs: bug #56438, the documentation should say which...


You are not allowed to post comments on this tracker with your current authentication level.

bug #56438: the documentation should say which flavor of regular expression is used

Submitted by:  Peter Liscovius <peterdd>
Submitted on:  Tue 04 Jun 2019 06:54:26 PM UTC  
Severity:  2 - Minor Status:  Fixed
Assigned to:  Benno Schulenberg <bens> Open/Closed:  Closed

( Jump to the original submission)

Sat 10 Aug 2019 12:23:58 PM UTC, comment #9: 

The documentation now says which flavor of regexes nano uses.  So this issue is fixed.

The thing from comment #8 (spaces between words not getting highlighted even though the rule 'color ,yellow " "' should highlight all spaces) is a different issue.  Please post it as a new issue.  (Which I cannot reproduce, by the way.  Please try not including all the *.nanorc files from the Cellar -- reduce your .nanorc to the bare essentials to reproduce the issue.)

Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Wed 19 Jun 2019 02:06:40 PM UTC, comment #8: 

> You are on a Mac?

At the moment, yes.

> And for you \t works in a regex?


I just used 'brew install nano' command.
Maybe this how its configured: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nano.rb

My .nanorc looks now like this:

include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"
syntax default
color ,green "^ +"
# a tab followed a space in the following regex
color ,green   "         +"
# at tab followed by a space in the following regex
color ,green   "[        ]+$"
color ,yellow " "

(current savane savannah.gnu.org converts tabs in verbatim sections. :-/)

Peter Liscovius <peterdd>
Wed 19 Jun 2019 06:32:57 AM UTC, comment #7: 


Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Thu 06 Jun 2019 05:55:11 PM UTC, comment #6: 

Well, I don't know what kind of ERE nano uses.  Nano uses gnulib, and its configure scripts do all kinds of tests, and as far as I can tell, this leads to the regex module from gnulib being used on most GNU/Linux systems and on all BSD systems.  If the regex module of gnulib uses POSIX EREs, then nano uses POSIX EREs.  If the gnulib module does not get used, then nano uses the regex functions provided by the system's libc (which then probably can do all that the gnulib module can do, so they are probably still POSIX EREs).

You are on a Mac?  And for you \t works in a regex?  Meaning that REG_ENHANCED is in effect?  Meaning that your build does not use the regex module from gnulib?  If so, did you force it to not use the gnulib module, or did ./configure decide by itself?

Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Thu 06 Jun 2019 02:29:41 PM UTC, comment #5: 

It is not that easy.

In other words: On what 'regex engine' nano depends? It just calls the grep version of the current operation system with params? Or use a lib or invented its own implementation of ERE?
If it is POSIX ERE then I would call it POSIX ERE, not just ERE.


Also there are several version of man grep: fsf version and POSIX version (man grep.1p) when posix man-pages are installed.

info grep regular opens the section you probably wanted in a linux shell, not on macos terminal.

There the output of info grep regular on a macos terminal is:

GREP(1)                   BSD General Commands Manual                  GREP(1)

     grep, egrep, fgrep, zgrep, zegrep, zfgrep -- file pattern searcher


But it points to re_format(7) in the description.

So man re_format on macos shows

RE_FORMAT(7)         BSD Miscellaneous Information Manual         RE_FORMAT(7)

     re_format -- POSIX 1003.2 regular expressions

     Regular expressions (``REs''), as defined in IEEE Std 1003.2 (``POSIX.2''), come in two forms: modern REs (roughly those of egrep(1); 1003.2 calls
     these ``extended'' REs) and obsolete REs (roughly those of ed(1); 1003.2 ``basic'' REs).  Obsolete REs mostly exist for backward compatibility in some
     old programs; they will be discussed at the end.  IEEE Std 1003.2 (``POSIX.2'') leaves some aspects of RE syntax and semantics open; `=' marks deci-
     sions on these aspects that may not be fully portable to other IEEE Std 1003.2 (``POSIX.2'') implementations.

And there is a section about Enhanced Extended Regular Expressions (and enhanced basic RE)

     When the REG_ENHANCED flag is passed to one of the regcomp() variants, additional features are activated.  Like the enhanced regex implementations in
     scripting languages such as perl(1) and python(1), these additional features may conflict with the IEEE Std 1003.2 (``POSIX.2'') standards in some
     ways.  Use this with care in situations which require portability (including to past versions of the Mac OS X using the previous regex implementation).

And there the \t is listed:

Literal Sequences (available for both enhanced basic and enhanced extended REs)
     Literals are normally just ordinary characters that are matched directly.  Under enhanced mode, certain character sequences are converted to specific

           \a  The ``bell'' character (ASCII code 7).

           \e  The ``escape'' character (ASCII code 27).

           \f  The ``form-feed'' character (ASCII code 12).

           \n  The ``new-line/line-feed'' character (ASCII code 10).

           \r  The ``carriage-return'' character (ASCII code 13).

           \t  The ``horizontal-tab'' character (ASCII code 9).

Peter Liscovius <peterdd>
Thu 06 Jun 2019 01:18:52 PM UTC, comment #4: 

Fixed in git, commit 94163761.  Thanks for reporting.

Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Thu 06 Jun 2019 11:38:52 AM UTC, comment #3: 

Did you look in the nanorc man page under the 'color' command?  There it says: "Display  all  pieces  of  text  that  match the extended regular expression 'regex'...".

I agree that this bit of text is hard to find, because the word 'color' occurs many times before it -- it would have been better if the 'color' command had a more distinct form, but alas, can't change that any more.  So I will add a second paragraph to the SYNTAX HIGHLIHTING section, to say that all regular expressions in nano are of the extended type (ERE).  And then refer the reader to 'info grep regular', because there is no point in duplicating a good manual.

As far as I know, \t is not part of any regex flavor.  At least, when I grep for "\t", it just finds each literal "t".  And when I use 'grep -P', it finds nothing.  So... what does \t mean in the Perl flavor of regular expressions?

Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Wed 05 Jun 2019 08:39:40 PM UTC, comment #2: 

> Where in the documentation do you suggest that this be documented?

I would expect man nanorc has a section about regular expressions for syntax highlighting. I always also prefer examples in man pages.
And provide there also a URL to the standard that is used (or nano tries to follow) for further info. And document differences between that standard vs nano (for instance not recognizing \t until version xxx.)

Maybe also within the editor for the regexp search/replace, but thats not my current issue as I do not regularly do complex regular expressions .. ;-)

> But you can achieve it in two:
> color ,green "\t +"
> color ,normal "\t"

Thank you, that  overwriting does the trick:

color ,green "^ +"
color ,green "\t +"
color ,green "[\t ]+$"
color ,yellow "\t"

Now nano colors mixed leading spaces and tabs in different colors and also ending tabs and spaces. Hooray!

Sure I would like to give them a bright background color like #eee or #ddd true color in light theme (#fff background) or similiar #111 #222 in a dark terminal theme...  bug #56445 ;-)

Peter Liscovius <peterdd>
Wed 05 Jun 2019 05:29:13 PM UTC, comment #1: 

Where in the documentation do you suggest that this be documented?

Nano uses Extended Regular Expressions (ERE), and thus what you want to do is not possible in one expression.  But you can achieve it in two:

  color ,green "\t +"
  color ,normal "\t"

Here \t needs to be actual tab characters, entered with M-V <Tab>.

(I've long thought about filing a request for nano to recognize \t, and have finally done so: bug #56443.)

Benno Schulenberg <bens>
Project AdministratorIn charge of this item.
Tue 04 Jun 2019 06:54:26 PM UTC, original submission:  

The documentation does not tell anything about what regular expression features or flavor/standard are used.

I tried to apply a 'find single spaces after tab character' with

color white,green "(?(?<=\t)( )+)" to a nanorc

but that entry is not accepted.

An example of mixed tabs with spaces and highlighting can be seen here (PCRE):


Peter Liscovius <peterdd>


Attached Files


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by peterdd (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-08-26 bens Open/ClosedOpen => Closed
    2019-08-10 bens StatusNeed Info => Fixed
        Discussion LockUnlocked => Locked
    2019-06-19 peterdd Attached File- => Added nano_tabs_and_spaces.png, #47109
    2019-06-19 bens StatusFixed => Need Info
    2019-06-06 bens StatusIn Progress => Fixed
    2019-06-06 bens StatusNone => In Progress
    2019-06-05 bens Severity3 - Normal => 2 - Minor
        Assigned toNone => bens
        Summarydocument which flavor of regular expression is used by nano => the documentation should say which flavor of regular expression is used

    Back to the top

    Powered by Savane 3.5