Getting my feet wet in Regular Expressions, and I’m having a difficult time getting this one to work.
I have a url as such:
/800-Flowers-inc-4124/18-roses-3123
Where 4124 is the business ID, and 3123 is the product ID.
The hard part for me is creating the capturing groups. Currently, my regex is as follows:
/(\d+)(?=/|$)/g
Unfortunately, that only selects the business ID, and doesn’t return the product ID.
Any help is greatly appreciated, and if you provide a regex, I would love if you could put a little explanation
thanks!
Your regex is fine, except since you’ve used the
/as the regex delimiter you need to escape it in the expression:Or, you can just use a different delimiter (e.g. @):
Depending on the language you’re using it’ll probably return the results in some sort of array, or there could be a ‘findAll’-type method instead of just ‘find’.