Y!RegExp quiz

This snippet is brought to you by Yahoo!Japan blogs. Quiz of the day: what is the RegExp meant to do and why does it fail?

if(img.match(/(.[jJ][pP][eE]?[gG]|.[gG][iI][fF]|.[pP][nN][gG])/)) {
return true;
}
return false;

(Yes, the variable name is a hint.)

Advertisements

6 thoughts on “Y!RegExp quiz

  1. So the dot matches of course any character, and they forgot the $ at the end, and they could have set the i modifier :)Did I forget something?Where did the creator learn regular expressions? (or maybe he didn't at all ๐Ÿ˜‰

  2. That's some peculiar coding

    function a(){
      if(foobar)
        return true;
      else
        return false;
    }
    
    function b(){
      if( a() )
        return true;
      else
        return false;
    }
    
    if( b() )
      return true;
    else
      return false;
    

    :p

  3. I'm guessing they're trying to determine whether a file is an image, but what happens when an image file has a different extension?BTW, the sign-up process for Opera Community appears to be almost broken/inaccessible: a captcha is presented with mixed case letters, but I couldn't proceed until I entered lowercase equivalents. It should either accept input that exactly matches the captcha, or it should ignore case.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s