Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
    
Worked Thanks !! – Praveen Sripati Jul 30 '12 at 10:45
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .