Avatar of sharingsunshine
sharingsunshine
Flag for United States of America

asked on 

Need Regex to find url's with underscores only

I have a website that has old links using underscores and the new s/w uses dashes instead.  I have redirects setup but Google won't index the pages that are using redirects.  So I want to find all links that have underscores.  Here is an example of the links:

<p>Herbs or supplements that help to relax the body will make a great difference if physical stress is involved, such as Nutri-Calm<a href="/product/nutri_calm_100_tablets_p_525/"></a>, <a href="/product/magnesium-250-mg/">Magnesium</a>, <a href="/product/lobelia_100_capsules_p_420/">Lobelia</a>, <a href="/product/lavender_fine_aoc_100_pure_essential_oil_p_35/">Lavender Essential Oil</a> or <a href="/product/geranium-15-ml-100-pure-essential-oil/">Stress-J</a>.   <a href="/product/tei-fu-essential-oil-blend-pocket-size/">Tei Fu</a> 

Open in new window

I put this regex together but it is still catching url's with dashes.
/product/(.+?)([^-]|_)(.+?)"

Open in new window

Please help me to fine tune the regex to find only those with underscores.
Regular ExpressionsWeb Development

Avatar of undefined
Last Comment
sharingsunshine

8/22/2022 - Mon