Reputation: 892
i am having a problem with some regex in a javascript function My string looks like this...
[Space]SomeString[Space][Tab]SomeString[Space][Tab][LineBreak]
SomeString[LineBreak]
[Space]SomeString[Space][Tab]SomeString[Space][Tab][LineBreak]
SomeString[LineBreak]
I want to remove the [Tab][LineBreak] but keep the [LineBreak] so my output would be
[Space]SomeString[Space][Tab]SomeString[Space]SomeString[LineBreak]
[Space]SomeString[Space][Tab]SomeString[Space]SomeString[LineBreak]
I have tried:
value.replace(/\t\n/g, '');
but that didn't work i also tried:
value.replace(/\s+/g, '');
but that removed all the line breaks
Can anyone help please? Thanks
Upvotes: 0
Views: 120
Reputation: 741
This will do the trick
str.replace(/\t(\r\n|\r|\n)/g,'');
Here is a demo fiddle.
Edit:
str = str.replace(/^\s|\t([\r\n]+)|([\r\n]+)\t|\s$/g,'');
Here is the "upgraded" example
Upvotes: 2