Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex: strip duplicates href tags

Status
Not open for further replies.

lizok

Programmer
Jan 11, 2001
82
0
0
US
Hello,

i have a text that contains hyperlinked works. some of them appear more than once making the text look very saturated with links. how can i (using regular expressions), strip duplicate a href tags? for reapeated items, hrefs are identical. i want to keep only the first occurance hyperlinked.

thank you
 
Well... I would look at parsing the page server-side (and that would include regex manipulation of the page contents, for sure). Maybe the first step would be to parse all <a href...>...</a> tags (and their content) into an array or some sort, then sort the array, then loop through it checking (and removing) for duplicates. Finally you could use the contents of the (de-duped) array as a source for outputting the rendered page markup. Doing it all using javascript is just inefficient and slow (compared to doing it server-side).

Hope that starts you off in a useful manner!

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top