azicchetti / jquerymobile-router

A router/controller for jquery mobile. Also adds support for client-side parameters in the hash part of the url. The routes handles regexp based routes. This plugin can be used alone or (better) with Backbone.js or Spine.js, because it's originally meant to replace their router with something integrated with jQM.
GNU General Public License v2.0
402 stars 69 forks source link

Docs: Mention that backslash isn't allowed in regular expressions #16

Closed kurtmilam closed 12 years ago

kurtmilam commented 12 years ago

OK, it didn't take me long to figure this out, but it did slow me down a little, since regexes that I was sure would match the URL hash were coming up empty.

A short mention of the fact that backslashes aren't allowed would be great.

Even better would be to find a way to make them work, but if that isn't possible, a mention in the docs would be helpful.

Thanks!

azicchetti commented 12 years ago

Could you please provide an example so that we can try to make it work?

I guess that a single backslash would need to be escaped a couple of times in order to work with the router. For instance: A\B should (untested!) be matched by "A\\B"

kurtmilam commented 12 years ago

Do you want a working code sample?

Here's a hash / regex pair that doesn't work for me.

Hash: #somepage?id=1234 Regex: #somepage\?id=([\d]*)

The first backslash escapes the question mark. The second (\d) matches any digit (0-9).

azicchetti commented 12 years ago

Il 11/01/2012 23:10, kurtmilam ha scritto:

Do you want a working code sample?

Here's a hash / regex pair that doesn't work for me.

Hash: #somepage?id=1234 Regex: #somepage\?id=([\d]*)

In this circumstance I would try:

somepage[?]id=(\d+)

kurtmilam commented 12 years ago

Yes, that works fine.

I'd still suggest that you mention it in the docs, since the backshlash is such an important character in regular expressions.

Thanks for looking into it.

azicchetti commented 12 years ago

Absolutely! I've just updated the doc, thank you very much.