Title: Problems with simple regex
Last modified: August 24, 2016

---

# Problems with simple regex

 *  Resolved [provdes](https://wordpress.org/support/users/provdes/)
 * (@provdes)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/problems-with-simple-regex/)
 * I’m having some issues with a simple regex that I can’t find any answers to.
 * I am redirecting URLs from an old html site to product categories on my WordPress/
   WooCommerce site. The old URLs are complex and rather than redirect every product
   I am matching a partial URL to the top level category.
 * [http://www.evatron.com/index-pag-products-cid-1-sid-1-l-2.html](http://www.evatron.com/index-pag-products-cid-1-sid-1-l-2.html)
 * Redirects to:
 * [http://evatron.com/product-category/desk-consoles/](http://evatron.com/product-category/desk-consoles/)
 * But I am only matching this part of the URL which references a product category
   number:
 * **/index-pag-products-cid-1**
 * Using this regex:
 * `/index-pag-products-cid-1(.*)`
 * Works lovely, until I get into double digits at the end of the original partial
   URL:
 * `/index-pag-products-cid-11(.*)`
 * Should go here:
 * [http://evatron.com/product-category/rectangular-potting-boxes/](http://evatron.com/product-category/rectangular-potting-boxes/)
 * But ends up at the same URL as the first redirect:
 * [http://evatron.com/product-category/desk-consoles/](http://evatron.com/product-category/desk-consoles/)
 * Am I doing something wrong with my regex markup? I tried disabling the original
   `/
   index-pag-products-cid-1(.*)` to test if then the double digit URLs worked, but
   it made no difference…
 * Any help would be much appreciated.
 * [https://wordpress.org/plugins/redirection/](https://wordpress.org/plugins/redirection/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [provdes](https://wordpress.org/support/users/provdes/)
 * (@provdes)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/problems-with-simple-regex/#post-6116342)
 * For anyone else’s information I resolved the issue.
 * I was using `(.*)` which matches any characters that fall _after_ the specified
   partial URL.
 * As my first partial URL ended with the number 1, it meant that this redirect 
   still took hold for any other partial URLs that ended with a teen number as the
   second digit was being grabbed by the regex `(.*)`
 * Fortunately in my case all my number in my URLs had a hyphen after them so all
   I had to do was make my initial partial URL a little more specific. So I changed
   it from:
 * `/index-pag-products-cid-1(.*)`
 * to
 * `/index-pag-products-cid-1-(.*)`
 * This made sure any URLs that contain teen numbers at the end of this portion 
   are redirected where they should be…
 * Boggled my brain for a few hours. Couldn’t see the wood for the trees…

Viewing 1 replies (of 1 total)

The topic ‘Problems with simple regex’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

## Tags

 * [regex](https://wordpress.org/support/topic-tag/regex/)

 * 1 reply
 * 1 participant
 * Last reply from: [provdes](https://wordpress.org/support/users/provdes/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/problems-with-simple-regex/#post-6116342)
 * Status: resolved