Regex how to match all end of line except blank line?

拟墨画扇 提交于 2019-12-23 15:47:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!