I found this javascript syntax highlighting file for nano on google code, downloaded it and included it in my /etc/nanorc file:

File: /usr/share/nano/js.nanorc

## all *js files  ( e.g. Firefox user.js, prefs.js )
## Old version
#syntax "jsfiles" "(\.|/|)js$"
#color green "//.*$" start="\/\*" end="\*\/"
#color blue "'(\\.|[^'])*'"
#color red ""(\\.|[^\"])*""
#color brightgreen "\<(true)\>"
#color brightred "\<(false)\>" "http\:\/\/.*$"
#color brightmagenta "[0-9](\\.|[^\"])*)"
## New updated taken from http://wiki.linuxhelp.net/index.php/Nano_Syntax_Highlighting
syntax "JavaScript" "\.(js)$"
## Default
color white "^.+$"
## Decimal, octal and hexadecimal numbers
color yellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\>"
## Floating point number with at least one digit before decimal point
color yellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
color yellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"
## Keywords
color green "\<(break|case|catch|continue|default|delete|do|else|finally)\>"
color green "\<(for|function|if|in|instanceof|new|null|return|switch)\>"
color green "\<(switch|this|throw|try|typeof|undefined|var|void|while|with)\>"
## Type specifiers
color red "\<(Array|Boolean|Date|Enumerator|Error|Function|Math)\>"
color red "\<(Number|Object|RegExp|String)\>"
color red "\<(true|false)\>"
## String
color brightyellow "L?\"(\\"|[^"])*\""
color brightyellow "L?'(\'|[^'])*'"
## Escapes
color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[bfnrt'\"\?\\]"
## Comments
color magenta start="/\*" end="\*/"
color magenta "//.*$"

However, now whenever I open any file using nano I am told there are errors. This line is printed for each and every line in the file which has a regular expression on it:

Error in /usr/share/nano/js.nanorc on line 11: Regex strings must begin and end with a " character

I am still able to open any file, and syntax highlighting still works for other filetypes, but there is no javascript highlighting.

Can anybody help me out here? I am very new to nano (and linux in general, really), but I can't see a problem with any of those regular expressions... they all begin and end with "s.


An edge-case but possible scenario:

If using Cygwin on Windows, ensure the line endings are Unix style (\n) as opposed to Windows style (\r\n). I encountered this exact issue, and this is the only link I found even on the StackExchange sites. It may be an edge case, but it leads to this exact problem

| improve this answer | |
  • this fixed the issue Regex strings must begin and end with a " character – Phate01 Dec 12 '19 at 17:50

In general, you could do the "divide and conquer" route. Make a copy of the file. Remove half, try the config. If the syntax has an error, it's in the half that's in the file - repeat (remove half). If not, it's in the half that you deleted. Use the half that you split out, and remove half from that, until you get to one line that's bad.

I don't know the file format, but my guess would be the line

#color red ""(\\.|[^\"])*""

It starts with ", then a " right away, closing it, then regex in between. Im guessing you need to escape the inner quotes:

#color red "\"(\\.|[^\"])*\""
| improve this answer | |
  • According to the error messages, every single regex string is in error. I get the same message for lines 11,13,15,17,18,20,21,22,24,25,26,28,29,31,33,34. The ones at the top are commented out anyway. – Luke Mar 18 '13 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.