Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Matching RE's

From: d4marcus::dtek::chalmers::se at: 22-Mar-2001 23:53

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