0

When I write a blog entry in Google blogger then a lot of entries like shown as below are getting inserted in HTML (not sure why).

<span id="textmarked_8" name="textmarker_9" style="background-color: yellow;"></span>

How I do I remove them? Note the numbers 8 and 9 have to be replaced by some regular expression. I am looking for a command in vi or some other easy command. BTW, I am using Ubuntu.

Thanks.

2

You should really use an HTML-parser not a regex (see past answers on this subject).

However if the XML has completely predictable content and formatting you can get away with something like

:%s/<span[^>]*><\/span>//

(untested) The important point here is that it tests for an empty span element that happens to be all on the same line. You could add a caret (^) at the start if the unwanted span elements always start at the beginning of a new line.

If you want to match id="textmarked_[0-9]* you can do that, I doubt it is necessary. Any empty span element probably serves no useful purpose regardless of it's attributes. The only exception I can think of is if some javascript later populates those elements.

| improve this answer | |
  • 1
    @PraveenSripati: Good, I'm glad it helped. Do read the linked article though - this bad habit (using regex on HTML) will bite back viciously sooner or later. – RedGrittyBrick Jul 30 '12 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.