Jump to content

railgun

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by railgun

  1. Sorry about your computer.  Everyone needs to have 3 or 4 spares.  Thanks again for your help.  I think I have muddled through it and come up with a workable, however un-elegant solution. I'll include it for posterity.  My goal was to have a filename in an exact format, but to NOT have any two non alphanumeric characters consecutive. So far the below seems to be working fine in PHP.

     

    $str = "ABC-12_e-f3.jpg";

     

    if ((preg_match('/^[A-Z]{3}\-\d{1,2}\_[A-Za-z0-9._-]+\.jpg$/', $str)) && (!preg_match('/[._-](?=[._-])/', $str))) {

    print "Good Filename";

    } else {

    print "Bad Filename";

    }

  2. Thanks for the reply.  I didn't realize that I had inadvertently taken the period, hyphen, and underscore out of the expression but that is the case. And the + following the {} is just inexperience.  My aim is to allow the above mentioned characters as part of the filename but just to NOT allow two of them consecutively.  So, with that in mind, and to try to further my regex education, when you get some spare time, tell me how in the blue blazes do you keep two consecutive periods or hyphens or underscores out of the filename?

  3. As you can tell from the expression, I am making sure that the filename of an image is in a particular format.  The trouble I'm having is with the look ahead assertion and trying to make sure that a period cannot follow another period. Then, after conquering that, I will also do the same for the other allowables.

     

    preg_match('/^[A-Z]{3}+\-+\d{1,2}+\_+[a-zA-Z0-9]+\.jpg$/', $filenameString);

     

    Thanks for your expertise.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.