Thread: Regex help for nanorc files.

  1. #1
    Registered User
    Join Date
    Apr 2019

    Regex help for nanorc files.


    I usually use nano text editor for my programming needs and have loved the text highlighting feature. It really makes programming much faster, and just by doing nothing by colour coding the different types of syntax.

    There is just one problem that bugs me, and I have tried to make it work, but I feel I have lost a lot of what I learned about regex (back in my PERL days).

    The problem arises when I'm using an HTML link in my code. The '//' in the address causes nano to comment out the rest of the address, like it was a comment.

    I would like to have nano comment out everything after '//' except when it is '//:'.

    My first work around was to change:
    color brightblue "//.*"
    to this:
    #color brightblue "//[[:space:]].*"
    It works, but requires all comments '//' to be followed immediately with a space '// '. But I don't like having to increase my keystrokes by 1/3 every time I want to comment out a few lines for debugging purposes.

    I was revisiting the problem when I came across the regex negation operator. It looks like it should be what I need to fix this problem, but I'm not able to get it work. Thinking it should work, I tried the following:
    #color brightblue "//(?!:).*"
    Can someone please shed some light on this for me?

    Last edited by Yonut; 05-11-2020 at 10:39 AM. Reason: fixed code.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Shouldn't you be worried by what is before the //, not what is after?

    is a url, whereas
    statement;// comment
    is a comment
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2019
    Wow, I really have to take the occasional nap.

    Ty for your comment, it lead me to the answer. First, I didn't realize I had the colon ':' in the wrong place. After that, I realized I could use the original code:

    color brightblue "//.*"
    And then just correct the url problem with:
    color brightyellow "://.*"
    As everything that would contain a url (or '://') would have to be a string.

    Ty for your assistance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. regex in c (posix regex)
    By baxy in forum C Programming
    Replies: 1
    Last Post: 11-16-2012, 01:15 PM
  2. img regex help
    By hawlpm3 in forum C Programming
    Replies: 1
    Last Post: 03-07-2011, 09:39 AM
  3. regex
    By l2u in forum C++ Programming
    Replies: 8
    Last Post: 10-09-2006, 10:45 AM
  4. <regex.h> regex syntax in C
    By battersausage in forum C Programming
    Replies: 7
    Last Post: 03-24-2004, 01:35 PM
  5. How is regex used?
    By Strider in forum C++ Programming
    Replies: 0
    Last Post: 12-14-2001, 08:15 AM

Tags for this Thread