Bunny Regex

By Deane Barker on March 2, 2006

Introducing BunnyRegex: easy regular expressions, and mini-languages inside of PHP: Here’s a great little regex library for PHP that uses a dead-simple syntax that someone should have thought of way, way before this.

include("BunnyRegex.php");
$pattern = new BunnyRegex();

$pattern->bol() // ^ 
->digit() // \d 
->exactly(4) // {4} 
->string('/') // / 
->digit() // \d 
->exactly(2) // {2} 
->string('/') // / 
->digit() // \d 
->exactly(2) // {2} 
->eol(); // $ 

$pattern->match('2006/02/28'); // returns true
$pattern->numberOfMatches('2006/02/28'); // returns 1
Gadgetopia

Comments

  1. I still prefer the string version (^\d{4}/\d{2}/\d{2}$). This makes me think of the chaining of the < < operator in the C++ standard library stream classes. Both are somewhat repurpusing the language syntax to mean other things. I'm not fond of it.

    And I wouldn’t want to have to write (or even worse: debug) big regular expressions as you can find in Markdown with a syntax like this. With so much verbosity it would be easy to get lost trying to understand the whole regex. But that was probably not the problem it was trying to solve.

    [Note: why is the coment preview eating the two plus in C++? I had to write them as character entities.]

  2. But we’re not all regex ninjas, Michel. What I’ve found with big regexes is that they’re easy to understand while you’re writing them, but when you go back to work with them later, they’re a pain to get back up-to-speed on.

    I’m sure, however, that Markdown has regexes that are a bit above the standard, so it’s not for everyone.

    why is the coment preview eating the two plus in C++? I had to write them as character entities.

    It’s your language, dude. You tell me.

  3. I can’t argue that current regular expression syntax is obscure and could be improved and made clearer. That is why big regexes in Markdown are all accompagnied by a comment explaining each part of them (list marker, blank line, link title …); this way they are a lot easier to decipher.

    why is the coment preview eating the two plus in C++? I had to write them as character entities.

    It’s your language, dude. You tell me.

    I’d bet it’s because the Show Preview button issues a GET XMLHttpRequest where pluses are not being encoded as %2b as they should and are thus converted to spaces at the revceiving end prior entering Markdown.

  4. I’d bet it’s because the Show Preview button issues a GET XMLHttpRequest where pluses are not being encoded as %2b as they should and are thus converted to spaces at the revceiving end prior entering Markdown.

    You just had to put it back on me didn’t you? Way to pass the buck, man.

    I’ll look at it.

  5. Good site. Thank you. http://ing.forect.be/ hanging http://beddi.facello.be/ childrens bedding and accessories http://gu.hmeter.be/ 1966 topps baseball http://e-car.gainbel.be/ wishing well http://ng.atavist.be/ animated congratulation cards http://inde.unquati.be/ collectandsave http://d-ki.gainbel.be/ christmas card kit http://ard.auntl.be/ topps http://p-ca.giglous.be/ larry fritsch http://nary.eurister.be/ cards stationary http://ard-i.feignet.be/ thank you cards with photo insert http://d-je.facello.be/ becket by jean http://oto.auntl.be/ how many photos can a 256mb card hold http://rd-ve.gtondily.be/ paperikoot http://he.ematio.be/ stitchery http://worl.enolina.be/ pokémon http://aptis.hmeter.be/ printable baptism card http://ra.facello.be/ discount photo insert christmas cards http://d-c.uviabi.be/ calling card world http://cloth.gainbel.be/ english childrens clothing

Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.