Regex how to match all end of line except empty line?
If I have text:
AAAAAA
BBBBBB
CCCCCC
DDDDDD
EEEEEE
FFFFFF
GGGGGG
HHHHHH
I want to match the entire end of the line except empty lines and replace the end of the line with a tab. [^\s]$
partially works, but also matches the last character of a nonblank string. [^^]$
does not work. What's the correct regular expression?
+3
TRX
source
to share
2 answers
You can use negative lookbehind regex:
/(?<!\s)$/mg
Demo version of RegEx
+3
anubhava
source
to share
You can use lookbehind for this purpose:
(?<=[^\s])$
See DEMO
+2
karthik manchala
source
to share