Hunt
Hunt

Reputation: 8425

Remove unwanted tags using regular expression

This is my text:

301 Roger Complex, Nr. Saint Martin Rd, NY ,380009<br /><a class="popsearchfont" href="javascript:jd_initialize(2, 1, 4);_clickTracker('viewmap','lspg');"><b>View Map</b></a>

I want to remove everything after <br /> so that it looks like as follows using regular expression:

301 Roger Complex, Nr. Saint Martin Rd, NY ,380009

Upvotes: 1

Views: 247

Answers (2)

Justin Morgan
Justin Morgan

Reputation: 30715

So it sounds like you want to either remove everything matching this:

/<br \/>.*$/i

Or keep everything matching this:

/^.*?(?=<br \/>)/i

Either one of these should work; just pick whatever you like better. Note that something like < br > is still valid HTML, so if you're not sure what the actual input will be like, you may want to consider changing <br \/> to <\s*br\s*\/?> or even <\s*br\b[^>]*>.

Upvotes: 1

Ravi Gupta
Ravi Gupta

Reputation: 6450

Can be done in Vim using a simple sed command.

:%s/<br \/>.*$//g

Upvotes: 2

Related Questions