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

C

chacallot

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.
 
J

Jürgen Exner

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
 
R

Randal L. Schwartz

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?
 
D

Dr.Ruud

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\/)/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top