FAQ
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

$ perl -le 'print "YES" if "training/webcasts/webcast_data/186/index.html" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
YES
$ perl -le 'print "YES" if "training/webcasts/webcast_data/186/" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
YES
$ perl -le 'print "YES" if "training/webcasts/webcast_data/186/foo.html" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!


I tried these:

Regex('^training/webcasts/webcast_data/(\d+)/(index.html)?$')

matches:
../186/index.html : yes
../186/foo.html : no
../186/ : no
../186 : no


Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')

matches:
../186/index.html : yes
../186/foo.html : yes
../186/ : yes
../186 : yes


Regex('^training/webcasts/webcast_data/(\d+)(/?index.html)?$')

matches:
../186/index.html : yes
../186/foo.html : yes
../186/ : yes
../186 : yes




--
Bill Moseley
moseley@hank.org

Search Discussions

  • Boris Ćeranić at Mar 1, 2007 at 11:08 pm

    On 01/03/07, Bill Moseley 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
  • Bill Moseley at Mar 2, 2007 at 12:13 am

    On Fri, Mar 02, 2007 at 12:08:42AM +0100, Boris ?erani? wrote:
    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:
    Yes, when tested in Perl it works that way, but in Catalyst in other
    cases it still matches. That's the problem.

    Seems that Catalyst first tries to match the full path, then tries to
    match a reduced path. Adding a bit of debugging to Regex.pm's match()
    method:

    Request = /training/webcasts/webcast_data/162/foo.html

    Checking [training/webcasts/webcast_data/162/foo.html]
    Checking [training/webcasts/webcast_data/162]
    *MATCHED*

    So that's why it's matchine when I don't want it to match.


    --
    Bill Moseley
    moseley@hank.org
  • Brian Kirkbride at Mar 2, 2007 at 12:30 am

    Bill Moseley wrote:
    Yes, when tested in Perl it works that way, but in Catalyst in other
    cases it still matches. That's the problem.

    Seems that Catalyst first tries to match the full path, then tries to
    match a reduced path. Adding a bit of debugging to Regex.pm's match()
    method:

    Request = /training/webcasts/webcast_data/162/foo.html

    Checking [training/webcasts/webcast_data/162/foo.html]
    Checking [training/webcasts/webcast_data/162]
    *MATCHED*

    So that's why it's matchine when I don't want it to match.
    This isn't a case that Args(0) would fix, is it?

    Best,
    Brian
  • Bill Moseley at Mar 2, 2007 at 5:59 pm

    On Thu, Mar 01, 2007 at 04:13:05PM -0800, Bill Moseley wrote:
    Seems that Catalyst first tries to match the full path, then tries to
    match a reduced path. Adding a bit of debugging to Regex.pm's match()
    method:

    Request = /training/webcasts/webcast_data/162/foo.html

    Checking [training/webcasts/webcast_data/162/foo.html]
    Checking [training/webcasts/webcast_data/162]
    *MATCHED*
    Ok, so is that a bug? Or am I not understanding the docs?

    # Regex

    sub bar : Regex('^item(\d+)/order(\d+)$') { }

    Matches any URL that matches the pattern in the action key, e.g.
    http://localhost:3000/item23/order42. The '' around the regexp is
    optional, but perltidy likes it. :)

    So it seems that would also match:

    http://localhost:3000/item23/order42/something.else

    but the "$" would indicate to me that it much only match the shorter
    string.


    --
    Bill Moseley
    moseley@hank.org
  • Michael Reece at Mar 2, 2007 at 7:43 pm
    i don't think it's a bug.


    Catalyst::Manual::Intro also says:

    You can pass variable arguments as part of the URL path, separated
    with forward slashes (/). If the action is a Regex or LocalRegex, the
    '$' anchor must be used. For example, suppose you want to handle /foo/
    $bar/$baz, where $bar and $baz may vary:

    sub foo : Regex('^foo$') { my ($self, $context, $bar, $baz) = @_; }
    [..snip..]

    If a Regex or LocalRegex action doesn't use the '$' anchor, the
    action will still match a URL containing arguments, however the
    arguments won't be available via @_.


    have you tried adding :Args(0) to the action?

    On Mar 2, 2007, at 9:59 AM, Bill Moseley wrote:
    On Thu, Mar 01, 2007 at 04:13:05PM -0800, Bill Moseley wrote:
    Seems that Catalyst first tries to match the full path, then tries to
    match a reduced path. Adding a bit of debugging to Regex.pm's
    match()
    method:

    Request = /training/webcasts/webcast_data/162/foo.html

    Checking [training/webcasts/webcast_data/162/foo.html]
    Checking [training/webcasts/webcast_data/162]
    *MATCHED*
    Ok, so is that a bug? Or am I not understanding the docs?

    # Regex

    sub bar : Regex('^item(\d+)/order(\d+)$') { }

    Matches any URL that matches the pattern in the action key, e.g.
    http://localhost:3000/item23/order42. The '' around the regexp is
    optional, but perltidy likes it. :)

    So it seems that would also match:

    http://localhost:3000/item23/order42/something.else

    but the "$" would indicate to me that it much only match the shorter
    string.


    --
    Bill Moseley
    moseley@hank.org


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/
    catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    ---
    michael reece :: software engineer :: mreece@vinq.com
  • Brian Kirkbride at Mar 2, 2007 at 10:07 pm

    Michael Reece wrote:
    i don't think it's a bug. <snip>
    have you tried adding :Args(0) to the action?
    That was my guess too, I've been bit by this problem before adding Args(0) to my
    actions.

    - Brian
  • Jon Schutz at Mar 1, 2007 at 11:17 pm
    How about this:

    m!^training/webcasts/webcast_data/(\d+)/(index.html|$)!

    On Thu, 2007-03-01 at 14:51 -0800, Bill Moseley 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

    $ perl -le 'print "YES" if "training/webcasts/webcast_data/186/index.html" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
    YES
    $ perl -le 'print "YES" if "training/webcasts/webcast_data/186/" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!'
    YES
    $ perl -le 'print "YES" if "training/webcasts/webcast_data/186/foo.html" =~ m!^training/webcasts/webcast_data/(\d+)/(index.html)?$!


    I tried these:

    Regex('^training/webcasts/webcast_data/(\d+)/(index.html)?$')

    matches:
    ../186/index.html : yes
    ../186/foo.html : no
    ../186/ : no
    ../186 : no


    Regex('^training/webcasts/webcast_data/(\d+)/?(index.html)?$')

    matches:
    ../186/index.html : yes
    ../186/foo.html : yes
    ../186/ : yes
    ../186 : yes


    Regex('^training/webcasts/webcast_data/(\d+)(/?index.html)?$')

    matches:
    ../186/index.html : yes
    ../186/foo.html : yes
    ../186/ : yes
    ../186 : yes


Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 1, '07 at 10:51p
activeMar 2, '07 at 10:07p
posts8
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase