Textmate/Regex: Strip whitespace from beginning/end of file

前端 未结 3 866
梦毁少年i
梦毁少年i 2021-02-04 22:59

I\'m trying to add a macro/command to Textmate for some file cleanup and the last tidbit I haven\'t figured out is simply to remove blank lines from the beginning and end of a f

3条回答
  •  轮回少年
    2021-02-04 23:24

    This regex will remove the whitespace at the beginning of the file

    Find ^[\r\n\t ]+ and replace with (nothing).

    And this one will remove the whitespace at the end

    Find [\r\n\t ]+$ and replace with (nothing).

    I've never used Textmate regular expressions. There can be a \s (whitespace) class you can use instead of [\r\n\t ]. Also, you might need to turn multi-line mode on, if there is one.

提交回复
热议问题