regexp assistance

Discussion in 'Perl Misc' started by mike, Oct 12, 2009.

  1. mike

    mike Guest

    Hi,

    I am trying to get files that looks like:

    xxxInds.java
    yyyReset.java
    zzzRespone.java

    I am using the following regexp:

    return unless -f $File::Find::name;
    /^.*Inds|Reset|Response\.java\z/s

    I get files with another file extension than java.

    Is \z not to match at the end of a string?

    br,

    //mike
    mike, Oct 12, 2009
    #1
    1. Advertising

  2. mike <> wrote:
    > /^.*Inds|Reset|Response\.java\z/s


    'z' isn't special in a RE, therefore the backslash is redundant.

    >I get files with another file extension than java.
    >
    >Is \z not to match at the end of a string?


    No, what gave you that idea?
    See 'perldoc perlre' and probably 'perldoc perlretut'.

    jue
    Jürgen Exner, Oct 12, 2009
    #2
    1. Advertising

  3. mike

    mike Guest

    On 12 Okt, 15:36, Jürgen Exner <> wrote:
    > mike <> wrote:
    > > /^.*Inds|Reset|Response\.java\z/s

    >
    > 'z' isn't special in a RE, therefore the backslash is redundant.
    >
    > >I get files with another file extension than java.

    >
    > >Is \z not to match at the end of a string?

    >
    > No, what gave you that idea?


    http://www.somacon.com/p127.php

    > See 'perldoc perlre' and probably 'perldoc perlretut'.
    >
    > jue
    mike, Oct 12, 2009
    #3
  4. mike

    mike Guest

    On 12 Okt, 15:57, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    > Jürgen Exner wrote:
    > > mike <> wrote:
    > >> /^.*Inds|Reset|Response\.java\z/s

    >
    > > 'z' isn't special in a RE, therefore the backslash is redundant.

    >
    > >> I get files with another file extension than java.

    >
    > >> Is \z not to match at the end of a string?

    >
    > > No, what gave you that idea?

    >
    > It's in table 5.7 (Alphanumeric Regex Metasymbols) of the camel book!
    >
    > BugBear


    My question is still not answered...

    //mike
    mike, Oct 12, 2009
    #4
  5. mike

    sreservoir Guest

    mike wrote:
    > Hi,
    >
    > I am trying to get files that looks like:
    >
    > xxxInds.java
    > yyyReset.java
    > zzzRespone.java
    >
    > I am using the following regexp:
    >
    > return unless -f $File::Find::name;
    > /^.*Inds|Reset|Response\.java\z/s


    this gets:
    anything with Inds in it
    anything with Reset in it
    anything that ends with Response.java

    > I get files with another file extension than java.
    >
    > Is \z not to match at the end of a string?


    Yes, though you might get "Response.java\n", iirc.

    Which probably still doesn't aswer your implicit question, but you
    didn't ask.

    --

    "Six by nine. Forty two."
    "That's it. That's all there is."
    "I always thought something was fundamentally wrong with the universe"
    sreservoir, Oct 12, 2009
    #5
  6. mike

    Marc Girod Guest

    On Oct 12, 2:25 pm, mike <> wrote:

    >         /^.*Inds|Reset|Response\.java\z/s


    Parentheses?

    /^.*(Inds|Reset|Response)\.java\z/s

    Marc
    Marc Girod, Oct 12, 2009
    #6
  7. On Oct 12, 10:45 am, Marc Girod <> wrote:
    > On Oct 12, 2:25 pm, mike <> wrote:
    >
    > >         /^.*Inds|Reset|Response\.java\z/s

    >
    > Parentheses?
    >
    > /^.*(Inds|Reset|Response)\.java\z/s
    >
    > Marc



    Parentheses will be the bane of me. I always seem to have too few or
    too many. The crux of such problem is that parentheses have two
    distinct purposes in regexes:

    (1) The normal grouping used in math and programming languages.

    (2) The "grab this part" function.

    Who invented regexes anyway, was it Larry Wall? I would have used
    angle brackets for the functionality (2) above.

    -Ramon
    Ramon F Herrera, Oct 12, 2009
    #7
  8. mike

    Guest

    On Mon, 12 Oct 2009 06:25:38 -0700 (PDT), mike <> wrote:

    >Hi,
    >
    >I am trying to get files that looks like:
    >
    >xxxInds.java
    >yyyReset.java
    >zzzRespone.java
    >
    >I am using the following regexp:
    >
    >return unless -f $File::Find::name;
    > /^.*Inds|Reset|Response\.java\z/s


    /^.*(?:Inds|Reset|Response)\.java$/s
    -sln
    , Oct 12, 2009
    #8
  9. mike

    Guest

    On Mon, 12 Oct 2009 08:31:35 -0700, wrote:

    >On Mon, 12 Oct 2009 06:25:38 -0700 (PDT), mike <> wrote:
    >
    >>Hi,
    >>
    >>I am trying to get files that looks like:
    >>
    >>xxxInds.java
    >>yyyReset.java
    >>zzzRespone.java
    >>
    >>I am using the following regexp:
    >>
    >>return unless -f $File::Find::name;
    >> /^.*Inds|Reset|Response\.java\z/s

    >
    > /^.*(?:Inds|Reset|Response)\.java$/s

    /^.*(?:Inds|Reset|Response)\.java$/
    -sln
    , Oct 12, 2009
    #9
  10. mike

    Guest

    On Mon, 12 Oct 2009 16:17:31 +0100, Ben Morrow <> wrote:

    >
    >Quoth Sherm Pendley <>:
    >> mike <> writes:
    >>
    >> > Is \z not to match at the end of a string?

    >>
    >> Yes, but $ is far more commonly used for that.

    >
    >The difference is important. /$/ will match before a newline at the end
    >of the string; /\z/ will not. When you are certain your strings won't
    >contain newlines, there is no difference, but once you start considering
    >using /m and /s you should also consider whether you need /\z/ instead
    >of /$/.
    >
    >Ben


    I guess \A\Z\z in multiple lines, mean "only" to be once.

    -sln
    , Oct 12, 2009
    #10
  11. On 2009-10-12 13:36, Jürgen Exner <> wrote:
    > mike <> wrote:
    >>I get files with another file extension than java.
    >>
    >>Is \z not to match at the end of a string?

    >
    > No, what gave you that idea?
    > See 'perldoc perlre' and probably 'perldoc perlretut'.


    Please open 'perldoc perlre' and search for \z.

    hp
    Peter J. Holzer, Oct 12, 2009
    #11
  12. bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    >Jürgen Exner wrote:
    >> mike <> wrote:
    >>> /^.*Inds|Reset|Response\.java\z/s

    >>
    >> 'z' isn't special in a RE, therefore the backslash is redundant.
    >>
    >>> I get files with another file extension than java.
    >>>
    >>> Is \z not to match at the end of a string?

    >>
    >> No, what gave you that idea?

    >
    >It's in table 5.7 (Alphanumeric Regex Metasymbols) of the camel book!


    I stand corrected. It is listed in perlre in the zero-width assertions
    category.

    jue
    Jürgen Exner, Oct 12, 2009
    #12
  13. mike

    Justin C Guest

    On 2009-10-12, mike <> wrote:
    > Is \z not to match at the end of a string?


    No, $ matches end of string. /^string$/

    Justin.

    --
    Justin C, by the sea.
    Justin C, Oct 13, 2009
    #13
  14. >>>>> "Peter" == Peter J Holzer <> writes:

    Peter> Please open 'perldoc perlre' and search for \z.

    "I keep searching for \z, but all I find is the end of string!"

    :)

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
    See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
    Randal L. Schwartz, Oct 14, 2009
    #14
  15. mike

    Steve C Guest

    Randal L. Schwartz wrote:
    >>>>>> "Peter" == Peter J Holzer <> writes:

    >
    > Peter> Please open 'perldoc perlre' and search for \z.
    >
    > "I keep searching for \z, but all I find is the end of string!"
    >
    > :)
    >



    My problem is that I've been searching for $ for years and never
    find enough.
    Steve C, Oct 14, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. trans.  (T. Onoma)
    Replies:
    21
    Views:
    226
    Kristof Neirynck
    Jan 18, 2005
  2. Greg Hurrell
    Replies:
    4
    Views:
    157
    James Edward Gray II
    Feb 14, 2007
  3. Joao Silva
    Replies:
    16
    Views:
    353
    7stud --
    Aug 21, 2009
  4. kelvlam

    RegExp assistance?

    kelvlam, Sep 13, 2006, in forum: Javascript
    Replies:
    4
    Views:
    80
    kelvlam
    Sep 14, 2006
  5. VUNETdotUS

    RegExp Assistance

    VUNETdotUS, Oct 17, 2007, in forum: Javascript
    Replies:
    3
    Views:
    66
    VUNETdotUS
    Oct 18, 2007
Loading...

Share This Page