# Routes requirements exclude one character

**URL:** <https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979>\
**Category:** Rails\
**Created:** [September 23, 2009, 9:49am UTC](https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979 "2009-09-23T09:49:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [September 23, 2009, 9:49am UTC](https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979/1 "2009-09-23T09:49:46Z")

</div>

Hi!

Consider the following route:  
map.detail “subscription\_plans/:provider/:plan”, :action =\>  
“detail”, :requirements =\> {:plan =\> /[^]+/}

I want this route to match any string _without_ a space character. So  
“Telfort-100” matches “Telfort 100” does not.

I believed this to be correct but it’s not. Including anchors (’\A’  
‘$’ etc) is not allowed. How else can I fix this?

Harm

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [September 23, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979/2 "2009-09-23T21:56:58Z")

</div>

The regexp you’ve specified here will match as long as there are at  
least two consecutive non-space characters. The only way I can think  
of to do what you’re looking for would be to add a route preceding  
this one which matches any :plan WITH a space, and routes it to an  
error page. EG:

map.bad\_detail “subscription\_plans/:provider/:plan”, :action =\>  
‘detail\_error’, :requirements =\> { :plan =\> /[]/ }  
map.detail “subscription\_plans/:provider/:plan”, :action =\> ‘detail’

–Matt J.

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [September 23, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979/3 "2009-09-23T22:30:44Z")

</div>

Matt J. wrote:

> The regexp you’ve specified here will match as long as there are at  
> least two consecutive non-space characters.

I would have thought so, but the routing docs suggest that the regex is  
implicitly anchored at both ends (look at the postalcode example).

> The only way I can think  
> of to do what you’re looking for would be to add a route preceding  
> this one which matches any :plan WITH a space, and routes it to an  
> error page.

That’s clever!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [September 24, 2009, 11:03am UTC](https://www.ruby-forum.com/t/routes-requirements-exclude-one-character/175979/4 "2009-09-24T11:03:08Z")

</div>

That _is_ clever!

I still believe Rails is in error here. The docs indeed do suggest  
that the stuff is anchored. Clearly it’s not. I’ll consider making a  
ticket.

Thanks for the input guys!

On Sep 23, 10:30 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-
