Maksim Morozov
Maksim Morozov

Reputation: 191

How to delete all SPANs?

I'm trying to remove all occurrences of <SPAN> and </SPAN> from a given text.

For example:

<span>Пн - Пт: 09:00-18:00</span><span>Сб: 09:00-13:00</span><span>Вс: выходной</span>

Here's what I've tried so far:

phonecatControllers.filter('htmlToPlaintext1', function() {
    return function(text) {
        return  String(text).replace('</span><span>', ' ');
    }
});

Upvotes: 0

Views: 146

Answers (2)

griffon vulture
griffon vulture

Reputation: 6764

For removing span with content:

String(text).replace(/<span>.*<\/span>/,'');

or if you want to leave content:

String(text).replace(/<span>([^<]+)<\/span>/g,'$1');

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

You could chain a couple more replaces to remove the starting and ending tag:

return String(text)
    .replace('</span><span>', ' ')
    .replace('<span>', '')
    .replace('</span>', '');

Upvotes: 0

Related Questions