I have a url string from which I want to capture all the words between the / delimiter:
So given this url:
"/way/items/add_items/sell_items":
I want to capture:
way
items
sell_items
add_items
If I do it like this:
'/way/items/sell_items/add_items'.match(/(\w+)/g)
=> [ 'way', 'items', 'sell_items', 'add_items' ]
It will give me an array back but with no capturing groups, why I do this instead:
new RegExp(/(\w+)/g).exec("/way/items/sell_items/add_items")
=> [ 'way', 'way', index: 1, input: '/way/items/sell_items/add_items' ]
But this only captures way .. I want it to capture all four words.
How do I do that?
Thanks
/.../is already aRegExpobject. You don't need to call the constructor.