Search for inconsistent line endings with a regex?



  • Is it possible to search for inconsistent line-endings in a file using a regular expression?

    It CAN happen that you get a mix of different line-ending types in a file, and it is usually WRONG when it happens.

    I’d like to detect this, using the line-ending on line 1 as the “gold standard”. Meaning, consider the line-ending on line 1 and if any of lines 2 thru the end of the file have a DIFFERENT line-ending, match it with a regex search.

    I’m not that great with regex, so I don’t know if this is possible or not. I’d appreciate someone either writing the regex for me (if it can be done), or giving me some pointers in the correct direction.



  • @Alan-Kilborn

    it is not really clear what you try to accomplish?
    Match the whole text, only the EOLs, only the line
    with the wrong EOLS (including/excluding).
    And what do you want to do afterwards?

    If you, for example, just want to change the eols I would
    use menu edit->eol conversion

    Cheers
    Claudia



  • @Claudia-Frank

    Hi Claudia,
    I would like to bookmark the lines with line-endings different than that of the first line of the file. I know how to bookmark with the Mark feature, but I just need a regex to feed it…



  • @Alan-Kilborn

    Hi Alan,

    currently I only have a solution for each eol.

    (?-s).*$(?!\r\n)   (lines not ending in win eol format \r\n)
    (?-s).*$(?!\n)   (lines not ending in unix eol format \n)
    (?-s).*$(?=\n|\r\n)   (lines not ending in old mac eol format \r)
    

    Cheers
    Claudia


Log in to reply