Why /(word){0}/ does not work?

Discussion in 'Perl Misc' started by chacallot@gmail.com, Nov 12, 2007.

  1. Guest

    Hi,

    I use a monitoring application, which allow use of perl regexp to
    filter which instance of something I want to monitor.
    In some case I want to monitor everything except one instance.
    Lets say it's every filesystem except /temp.
    The monitoring software allow perl regexp but not negating them.

    So I tried /(\/temp){0}/ but it doesnt work (every filesystem is
    monitored /temp included).

    Why is it it doesnt work?
    Is /^(?:(?!\/temp).)*$/ my only chance to do this right? Looks insanly
    obfuscated to me, but if you this it's the rite way to do it, I may
    try to understand it ....

    Regards,
    Chacallot.
     
    , Nov 12, 2007
    #1
    1. Advertising

  2. wrote:
    > So I tried /(\/temp){0}/ but it doesnt work (every filesystem is
    > monitored /temp included).


    The usual terminology for REs is "to match", not "to monitor". Therefore I
    am not sure about if you are complaining that /(\/temp){0}/ matches '/temp'
    or doesn't match '/temp'.

    However, _I_ read /(\/temp){0}/ as zero consecutive matches of /(\/temp)/
    which would match exactly the same strings as the empty RE //, e.g. it will
    match every string.

    > Why is it it doesnt work?


    But it does work. It matches zero repetitions of the preceeding RE.

    jue
     
    Jürgen Exner, Nov 12, 2007
    #2
    1. Advertising

  3. >>>>> "chacallot" == chacallot <> writes:

    chacallot> So I tried /(\/temp){0}/ but it doesnt work (every filesystem is
    chacallot> monitored /temp included).

    Indeed. The string "a" matches /a{0}/, because "a" has a match for zero
    instances of 'a', which is the same as the empty string, which every string
    has.

    Why would you expect it to do something different?

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
     
    Randal L. Schwartz, Nov 13, 2007
    #3
  4. Dr.Ruud Guest

    Randal L. Schwartz schreef:
    > chacallot:


    > chacallot> So I tried /(\/temp){0}/ but it doesnt work (every
    > filesystem is chacallot> monitored /temp included).
    >
    > Indeed. The string "a" matches /a{0}/, because "a" has a match for
    > zero instances of 'a', which is the same as the empty string, which
    > every string has.
    >
    > Why would you expect it to do something different?


    I actually like chacallot's train of thought. He/She wants the number of
    (possible) matches to be 0.

    0 * 0 = 0, so why is a beggar happy if there are zero days on which he
    received zero Euros?


    chacallot, did you try this? !/^\/temp\//

    If your software only allows unnegated Perl /regexen/:

    /^(?!=\/temp\/)/

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Nov 13, 2007
    #4
    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. jblazi
    Replies:
    5
    Views:
    460
    jblazi
    Aug 16, 2004
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    505
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    992
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,263
    Smokey Grindel
    Dec 2, 2006
  5. TechCrazy
    Replies:
    12
    Views:
    189
    John Bokma
    Jun 29, 2005
Loading...

Share This Page