简体   繁体   中英

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>', ' ');
    }
});

For removing span with content:

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

or if you want to leave content:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM