# Retrieve a capture group in routing?

**URL:** <https://www.ruby-forum.com/t/retrieve-a-capture-group-in-routing/131927>\
**Category:** Rails\
**Created:** [March 14, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/retrieve-a-capture-group-in-routing/131927 "2008-03-14T14:01:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 14, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/retrieve-a-capture-group-in-routing/131927/1 "2008-03-14T14:01:35Z")

</div>

Hi,

I’m trying to retrieve a capture group from a regular expression for a  
given route. Here’s the code:

map.category ‘:category’, :controller =\> ‘product’, :action =\>  
‘list’, :requirements =\> { :category =\> /[\w|-]+(-\d\*)?/}

I’d like to capture the end (-\d\*) inside “:page” to match “flowers”  
but also “flowers-p2”, “flowers-p3” etc for pages numbers. I’d like to  
make it pass the following test:

assert\_routing “flowers-p2”, :controller =\> ‘product’, :action =\>  
‘list’, :category =\> ‘flowers’, :page =\> 2  
assert\_routing “flowers”, :controller =\> ‘product’, :action =\>  
‘list’, :category =\> ‘flowers’

Does anyone knows if it’s possible to achieve this (and how) ?

## Thibaut Barrère / LoGeek

[http://blog.logeek.fr](http://blog.logeek.fr) - learning content for developers  
[http://evolvingworker.com](http://evolvingworker.com) - tools for a better day
