问题
If I have text:
AAAAAA
BBBBBB
CCCCCC
DDDDDD
EEEEEE
FFFFFF
GGGGGG
HHHHHH
I want to match all end of line except the blank lines and replace the end of line to tab. [^\s]$ partly works, but it also matches the last character of non-blank line. [^^]$ does not work. What is the correct regex?
回答1:
You can use negative lookbehind regex:
/(?<!\s)$/mg
RegEx Demo
回答2:
You can use lookbehind for this purpose:
(?<=[^\s])$
See DEMO
来源:https://stackoverflow.com/questions/30492293/regex-how-to-match-all-end-of-line-except-blank-line