vacpartswarehouse
asked on
JavaScript / jQuery RegEx Replacement
Hello,
I'm trying to use jQuery to replace some extraneous data that's hard-coded into a CMS I'm using. The text contains anchor links, but is displayed as such:
I'm trying to cut it down to display like this, but with the proper link attached to the last item:
I tried using this code
and got the following, all in plain text
I'm pretty inexperienced in both jQuery and regular expressions, so I'm sure I'm missing something simple, but I don't know what. I've attached the test file I'm using in case I'm missing something there.
Thank you in advance for your help,
B
I'm trying to use jQuery to replace some extraneous data that's hard-coded into a CMS I'm using. The text contains anchor links, but is displayed as such:
PANASONIC > Panasonic Upright Vacuums > MC-V5241-02
PANASONIC > Panasonic Upright Vacuums > MC-UL675-00
PANASONIC > Panasonic Upright Vacuums > MC-UL671-00
I'm trying to cut it down to display like this, but with the proper link attached to the last item:
>> MC-V5241-02
>> MC-UL675-00
>> MC-UL671-00
I tried using this code
<div>
<a href="http://www.vacpartswarehouse.com/PANASONIC-vacuums-bags-belts-brushes-parts-and-accessories-s/124.htm"> PANASONIC</a> > <a href="http://www.VacPartsWarehouse.com/Panasonic-Upright-Vacuums-s/5385.htm" title="Panasonic Upright Vacuums"> Panasonic Upright Vacuums</a> > <a href="http://www.VacPartsWarehouse.com/MC-V5241-02-s/5411.htm" title="MC-V5241-02"> MC-V5241-02</a><br />
<a href="http://www.vacpartswarehouse.com/PANASONIC-vacuums-bags-belts-brushes-parts-and-accessories-s/124.htm"> PANASONIC</a> > <a href="http://www.VacPartsWarehouse.com/Panasonic-Upright-Vacuums-s/5385.htm" title="Panasonic Upright Vacuums"> Panasonic Upright Vacuums</a> > <a href="http://www.VacPartsWarehouse.com/MC-UL675-00-s/5424.htm" title="MC-UL675-00"> MC-UL675-00</a><br />
<a href="http://www.vacpartswarehouse.com/PANASONIC-vacuums-bags-belts-brushes-parts-and-accessories-s/124.htm"> PANASONIC</a> > <a href="http://www.VacPartsWarehouse.com/Panasonic-Upright-Vacuums-s/5385.htm" title="Panasonic Upright Vacuums"> Panasonic Upright Vacuums</a> > <a href="http://www.VacPartsWarehouse.com/MC-UL671-00-s/5425.htm" title="MC-UL671-00"> MC-UL671-00</a><br />
</div>
<script>
jQuery('div').each(function(){
var div = $(this);
div.html(
div.text().replace('<a href="http://www\.vacpartswarehouse.com\.com/(((?!/).)*)/\d{3,4}\.htm">(((?!</a>).)*)</a> ', ''
)
)
});
</script>
and got the following, all in plain text
PANASONIC > Panasonic Upright Vacuums > MC-V5241-02 PANASONIC > Panasonic Upright Vacuums > MC-UL675-00 PANASONIC > Panasonic Upright Vacuums > MC-UL671-00
I'm pretty inexperienced in both jQuery and regular expressions, so I'm sure I'm missing something simple, but I don't know what. I've attached the test file I'm using in case I'm missing something there.
Thank you in advance for your help,
B
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked perfectly! Thank you so much for your help!
which is find an string like <a href=.....\d{3,4}.>ignore stuff in middle(continuematching:)<
so it strips all that out.
maybe you can try matching the 3 instances of link : (ie href="(link)"), and also match the 3 anchor text strings, and then do something like this.
str.replace('newregex','&g
Keep that in mind, sorry it's not a more specific solution but javascript regex's isn't my strong suit.