[Catalyst] Regex -- optional index.html

Boris Ćeranić zextra at gmail.com
Thu Mar 1 23:08:42 GMT 2007


On 01/03/07, Bill Moseley <moseley at hank.org> wrote:
> I want to match these two (not using Chained, btw):
>
>     /training/webcasts/webcast_data/186/
>     /training/webcasts/webcast_data/186/index.html
>
> But not this:
>
>     /training/webcasts/webcast_data/186/foo.html
>

(snip)

>
>
> I tried these:
>
(snip)

>     Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')
>
>         matches:
>             ../186/index.html   : yes
>             ../186/foo.html     : yes
>             ../186/             : yes
>             ../186              : yes
>
>
(snip)

Actually, this one works for me quite well - it should work fine for
following scenarios:

.../186
.../186/
.../186/index.html

In any other case, it will fail, as you can see:

$ perl -e 'print "YES" if "webcast_data/186" =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print "YES" if "webcast_data/186/" =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print "YES" if "webcast_data/186/index.html" =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'
YES

$ perl -e 'print "YES" if "webcast_data/186/asdf.html" =~
m|^webcast_data/(\d+)/?(index\.html)?$|;'


Regards,
Boris



More information about the Catalyst mailing list