en44no
en44no

Reputation: 63

Remove spaces but only between one string to another string

I am working in an editor and I need that between two labels there is no space, for example if I write enter image description here I need to remove all spaces after the opening tag and before the closing tag.

So if I write this I would just like to remove those spaces between ? and the end of the label enter image description here

But I only want to remove the spaces between the beginning of the tag and the first letter and the spaces between the last letter and the end of the tag. If then the user adds a lot of spaces between the letters I don't care.

Basically I would need to find what is between the opening of the label and the first letter and then I would need to find what is between the last letter and the closing of the label and in both cases delete any spaces that exist

Any ideas? Thank you so much!

Upvotes: 0

Views: 74

Answers (1)

Liam-Nothing
Liam-Nothing

Reputation: 167

You can detect it with regex : +<\/

const p = '<p>Hello world !                   </p>';
const regex = / +<\//i;
console.log(p);
console.log(p.replace(regex, '</'));

Upvotes: 1

Related Questions