Alex
Alex

Reputation: 2198

Replace linebreak in the end of string using regexp

Lets say I have JavaScript variable with a string as value like thi

var string;
string = "ushjsb\n laKDJV\n";

How can I by using regexp delete ONLY the last linebreak?

Upvotes: 1

Views: 34

Answers (1)

Griffith
Griffith

Reputation: 3217

Use:

string = string.replace(/\n+$/, "")

Upvotes: 2

Related Questions