strpos - and multiple needles?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Roberts

    #16
    Re: strpos - and multiple needles?

    My Pet Programmer <anthony@mypetp rogrammer.comwr ote:
    >
    >preg_match('/^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![
    >]))*(\.[a-zA-Z]{2,6})$/', $filename);
    >
    >That one should only match valid filenames.
    There are two things here I don't understand. First, I don't understand
    what you are trying to do with (?<![ ]). (I assume there was a space in
    there that caused the line to wrap.) As I read it, that says "fail if the
    last character of the previous match was a space", but since the pattern
    before it matches all the characters in the pattern after it, I don't see
    how it could ever take effect.

    Second, I don't get what you are trying to do with (\.[a-zA-Z]{2,6}). Is
    that supposed to be matching an extension? That fails for "test.c".

    Also, that requires a drive letter. Was that your intent?
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    • Anthony Levensalor

      #17
      Re: strpos - and multiple needles?

      Tim Roberts said:
      My Pet Programmer <anthony@mypetp rogrammer.comwr ote:
      >preg_match('/^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![
      >]))*(\.[a-zA-Z]{2,6})$/', $filename);
      >>
      >That one should only match valid filenames.
      >
      There are two things here I don't understand. First, I don't understand
      what you are trying to do with (?<![ ]). (I assume there was a space in
      there that caused the line to wrap.) As I read it, that says "fail if the
      last character of the previous match was a space", but since the pattern
      before it matches all the characters in the pattern after it, I don't see
      how it could ever take effect.
      >
      Second, I don't get what you are trying to do with (\.[a-zA-Z]{2,6}). Is
      that supposed to be matching an extension? That fails for "test.c".
      >
      Also, that requires a drive letter. Was that your intent?
      Actually, I made a mistake in posting that, grabbed a regExp from a
      completely different RegEx scheme. I thought you were looking for a
      windows workaround, and I completely spaced it and gave you one of their
      ..NET ones. Sorry about that.

      This one is the one I meant to hand off.
      preg_match('![^A-Z0-9_\.]!i',$filename)

      If it matches, then the filename is no good, ok otherwise
      Test cases:

      lib.so - Ok
      tbl_status - Ok
      my file is cool.txt NOT Ok
      \ this- isn't value NOT Ok
      text.c - Ok
      foo - Ok
      superlong_with_ underscores.png - Ok
      ILikeTrucks!.jp g NOT Ok

      REALLY sorry about the mix-up.

      ~A!

      --
      Anthony Levensalor
      anthony@mypetpr ogrammer.com

      Only two things are infinite, the universe and human stupidity,
      and I'm not sure about the former. - Albert Einstein

      Comment

      • Jerry Stuckle

        #18
        Re: strpos - and multiple needles?

        Anthony Levensalor wrote:
        Tim Roberts said:
        >My Pet Programmer <anthony@mypetp rogrammer.comwr ote:
        >>preg_match( '/^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![
        >>]))*(\.[a-zA-Z]{2,6})$/', $filename);
        >>>
        >>That one should only match valid filenames.
        >>
        >There are two things here I don't understand. First, I don't understand
        >what you are trying to do with (?<![ ]). (I assume there was a space in
        >there that caused the line to wrap.) As I read it, that says "fail if
        >the
        >last character of the previous match was a space", but since the pattern
        >before it matches all the characters in the pattern after it, I don't see
        >how it could ever take effect.
        >>
        >Second, I don't get what you are trying to do with (\.[a-zA-Z]{2,6}). Is
        >that supposed to be matching an extension? That fails for "test.c".
        >>
        >Also, that requires a drive letter. Was that your intent?
        Actually, I made a mistake in posting that, grabbed a regExp from a
        completely different RegEx scheme. I thought you were looking for a
        windows workaround, and I completely spaced it and gave you one of their
        .NET ones. Sorry about that.
        >
        This one is the one I meant to hand off.
        preg_match('![^A-Z0-9_\.]!i',$filename)
        >
        If it matches, then the filename is no good, ok otherwise
        Test cases:
        >
        lib.so - Ok
        tbl_status - Ok
        my file is cool.txt NOT Ok
        \ this- isn't value NOT Ok
        text.c - Ok
        foo - Ok
        superlong_with_ underscores.png - Ok
        ILikeTrucks!.jp g NOT Ok
        >
        REALLY sorry about the mix-up.
        >
        ~A!
        >
        A space is also valid in Windows.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Tim Roberts

          #19
          Re: strpos - and multiple needles?

          Anthony Levensalor <anthony@mypetp rogrammer.comwr ote:
          >
          >If it matches, then the filename is no good, ok otherwise
          >Test cases:
          >
          >lib.so - Ok
          >tbl_status - Ok
          >my file is cool.txt NOT Ok
          >\ this- isn't value NOT Ok
          >text.c - Ok
          >foo - Ok
          >superlong_with _underscores.pn g - Ok
          >ILikeTrucks!.j pg NOT Ok
          I guess this depends on your definition of "no good". Both "my file is
          cool.txt" and "ILikeTrucks!.j pg" are valid file names on both Windows and
          Unix.
          --
          Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          Working...