TRX
TRX

Reputation: 747

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

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?

Upvotes: 3

Views: 804

Answers (2)

anubhava
anubhava

Reputation: 784958

You can use negative lookbehind regex:

/(?<!\s)$/mg

RegEx Demo

Upvotes: 3

karthik manchala
karthik manchala

Reputation: 13640

You can use lookbehind for this purpose:

(?<=[^\s])$

See DEMO

Upvotes: 2

Related Questions