[REBOL] Re: Matching RE's
From: jelinem1:nationwide at: 23-Mar-2001 8:43
>> find/case/any/match "user.r" "*.r"
== ".r"
>> find/case/any/match "user.r" "*^.r"
== ".r"
>> find/any/match "user.r" "*.r"
== ""
>> index? find/any/match "user.r" "*.r"
== 7
/case seems to be presenting a problem.
You might try viewing just the return from 'find, and getting this 'index,
to see what is happening in abit more detail. Hopefully this will help you
understand what is going on.
>> find/case/any/match "user qwerty r" "*gargler"
== none
>> find/case/any/match "user qwerty r" "*garglr"
== ""
>> find/case/any/match "user qwerty r" "*ggly"
== " r"
That totally boggles my mind. After staring at it for awhile I can almost
see what it's doing, but it's certainly not the behavior I initially
expected.
- Michael Jelinek
Marcus Petersson <[d4marcus--dtek--chalmers--se]>@rebol.com on 03/22/2001
04:53:33 PM
From: Marcus Petersson <[d4marcus--dtek--chalmers--se]>@rebol.com on 03/22/2001
04:53 PM
Please respond to [rebol-list--rebol--com]
Sent by: [rebol-bounce--rebol--com]
To: [rebol-list--rebol--com]
cc:
Subject: [REBOL] Matching RE's
Warning! This mail contains a lot of whining. Don't read it if you easily
get bored. You have been warned, so bear with me.
Ok, so I start out thinking this will work:
>> "" = find/case/any/match "user.r" "*.r"
== false
Hmm, so the dot is a wildcard (equal to ?) and needs to be escaped:
>> "" = find/case/any/match "user.r" "*^.r"
== false
So it didn't work, let's try another RE construct:
= find/case/any/match "user.r" "*[.]r"
== true
Aha, that looks better, but let's check it first:
>> "" = find/case/any/match "user" "*[.]r"
== true
Oh no! The dot is still acting as a wildcard. What to do now?
Perhaps we can escape it within the blocks:
>> "" = find/case/any/match "user" "*[^.]r"
== true
Nope, didn't work. Let's try something else:
>> "" = find/case/any/match "user" "*[\.]r"
== false
>> "" = find/case/any/match "user.r" "*[\.]r"
== true
Aha, this could be it! But wait, perhaps... :
>> "" = find/case/any/match "user\r" "*[\.]r"
== true
Ouch, it seems to be a choice between backslash and dot. Or is it?
>> "" = find/case/any/match "user r" "*[\.]r"
== true
AARGH! Does it even work at all?
>> "" = find/case/any/match "user qwerty r" "*[ gargle ]r"
== true
Double-AARGH! Oh well, whatever those brackets do, I better stop using
them. Let's see... :
>> "" = find/case/any/match "user qwerty r" "*gargler"
== false
Phew, I was starting to worry. Let's check again:
>> "" = find/case/any/match "user qwerty r" "*garglr"
== true
What???!!! Oh well, before we give, better check the PDF. Hmm, seems they
have put /match before /any there. Wonder why... :
>> "" = find/case/match/any "user qwerty r" "*garglr"
== true
Nope. Oh well, one last try:
>> "" = find/match/any "user qwerty r" "*garglr"
== false
Yes! This is it, it was a problem with /case. So we get:
>> "" = find/match/any "user.r" "*.r"
== true
>> "" = find/match/any "user" "*.r"
== false
Good good. On the other hand, we also get:
>> "" = find/match/any "user.r" "*.R"
== true
Not good. What if we put /case back in there:
>> "" = find/match/any/case "user.r" "*.R"
== false
>> "" = find/match/any/case "user.r" "*.r"
== false
And so we're back where we started. Sigh, I guess I better write a RE to
Rebol parserule translator. Unless such a thing exists already...?
Some other examples:
>> find/case/any "user.R" '*r.R
== none
>> find/case/any "user.R" '*r.*
== none
>> find/case/any "user.R" '*r.r
== "user.R"
>> find/case/any "user.R" '*r.?
== "user.R"
Only the last one is correct. That pretty much says it all.
Marcus
------------------------------------
If you find that life spits on you
calm down and pretend it's raining