Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Regex - Problem

    Hello!

    I have this RegEx:
    /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i

    Now, I want to exlude on the end of a String the formats .gif / .jpg /
    ..png / .exe / .zip / .rar

    How I can this add to my regex ?

    Thanks for help!

    Sincerly!
    aeuglein Guest

  2. Similar Questions and Discussions

    1. Regex problem
      Hi there, I have a regex problem. Basicly I do not want to match: /dir/test/contact.html But I do want to match: /test/contact.html
    2. [PHP] regex problem
      So, what you want is to pretty much use this regex /^(.*)(+)\/(+)$/ when matched on this URI, the backreferences will contain \\1 partner/...
    3. [PHP] regex problem
      * Thus wrote Merlin (news.groups@web.de): I'm not sure what you expect since this *is* a php mailing list. Mod rewrite is a powerful tool and...
    4. [PHP] regex problem
      So ^+/* or ^!(partner/) Merlin wrote:
    5. [PHP] regex problem
      That's if($string == 'test/contact.html') of course... :) it could be if($string == "test/contact.html")
  3. #2

    Default Re: Regex - Problem

    aeuglein wrote:
    > I have this RegEx:
    > /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i
    >
    > Now, I want to exlude on the end of a String the formats .gif / .jpg /
    > .png / .exe / .zip / .rar
    >
    > How I can this add to my regex ?
    Not being all that great with regex myself, I think this may do the
    trick (or at least give you some ideas):

    /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(jpg|gif|png|exe|zip|rar)){0})/i

    --
    Justin Koivisto - [email]spam@koivi.com[/email]
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Justin Koivisto Guest

  4. #3

    Default Re: Regex - Problem

    On 9 Oct 2003 05:35:23 -0700, [email]sdz@gmx.de[/email] (aeuglein) wrote:
    >I have this RegEx:
    >/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i
    >
    >Now, I want to exlude on the end of a String the formats .gif / .jpg /
    >.png / .exe / .zip / .rar
    >
    >How I can this add to my regex ?
    Assuming Perl-compatible regexes due to the use of \w.

    If you want it in one regex, add a zero-width negative look-ahead assertion to
    the end.

    (Completely untested:)

    /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/]).*(?!\.(?:gif|jpg|png|exe|zip|rar))$/i

    The useful Perl module YAPE::Regex::Explain comes out with this explanation:

    The regular expression:

    (?-imsx:/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/]).*(?!\.(?:gif|jpg|png|exe|zip|rar))$/i)

    matches as follows:

    NODE EXPLANATION
    ----------------------------------------------------------------------
    (?-imsx: group, but do not capture (case-sensitive)
    (with ^ and $ matching normally) (with . not
    matching \n) (matching whitespace and #
    normally):
    ----------------------------------------------------------------------
    / '/'
    ----------------------------------------------------------------------
    ( group and capture to \1:
    ----------------------------------------------------------------------
    [\w]+ any character of: word characters (a-z,
    A-Z, 0-9, _) (1 or more times (matching
    the most amount possible))
    ----------------------------------------------------------------------
    : ':'
    ----------------------------------------------------------------------
    \/ '/'
    ----------------------------------------------------------------------
    \/ '/'
    ----------------------------------------------------------------------
    [\w-?&;#~=\.\/\@]+ any character of: word characters (a-z,
    A-Z, 0-9, _), '-', '?', '&', ';', '#',
    '~', '=', '\.', '\/', '\@' (1 or more
    times (matching the most amount
    possible))
    ----------------------------------------------------------------------
    [\w\/] any character of: word characters (a-z,
    A-Z, 0-9, _), '\/'
    ----------------------------------------------------------------------
    ) end of \1
    ----------------------------------------------------------------------
    .* any character except \n (0 or more times
    (matching the most amount possible))
    ----------------------------------------------------------------------
    (?! look ahead to see if there is not:
    ----------------------------------------------------------------------
    \. '.'
    ----------------------------------------------------------------------
    (?: group, but do not capture:
    ----------------------------------------------------------------------
    gif 'gif'
    ----------------------------------------------------------------------
    | OR
    ----------------------------------------------------------------------
    jpg 'jpg'
    ----------------------------------------------------------------------
    | OR
    ----------------------------------------------------------------------
    png 'png'
    ----------------------------------------------------------------------
    | OR
    ----------------------------------------------------------------------
    exe 'exe'
    ----------------------------------------------------------------------
    | OR
    ----------------------------------------------------------------------
    zip 'zip'
    ----------------------------------------------------------------------
    | OR
    ----------------------------------------------------------------------
    rar 'rar'
    ----------------------------------------------------------------------
    ) end of grouping
    ----------------------------------------------------------------------
    ) end of look-ahead
    ----------------------------------------------------------------------
    $ before an optional \n, and the end of the
    string
    ----------------------------------------------------------------------
    /i '/i'
    ----------------------------------------------------------------------
    ) end of grouping
    ----------------------------------------------------------------------

    --
    Andy Hassall (andy@andyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage analysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  5. #4

    Default Re: Regex - Problem

    On Thu, 09 Oct 2003 15:50:50 GMT, Justin Koivisto <spam@koivi.com> wrote:
    >aeuglein wrote:
    >
    >> I have this RegEx:
    >> /([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i
    >>
    >> Now, I want to exlude on the end of a String the formats .gif / .jpg /
    >> .png / .exe / .zip / .rar
    >>
    >> How I can this add to my regex ?
    >
    >Not being all that great with regex myself, I think this may do the
    >trick (or at least give you some ideas):
    >
    >/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(jpg|gif|png|exe|zip|rar)){0})/i
    (\.(jpg|gif|png|exe|zip|rar)){0})

    There's always a zero length match for this; zero occurrences of a pattern is
    a zero length string, and there's plenty of those in between characters :-)

    --
    Andy Hassall (andy@andyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage analysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  6. #5

    Default Re: Regex - Problem

    Andy Hassall wrote:
    > On Thu, 09 Oct 2003 15:50:50 GMT, Justin Koivisto <spam@koivi.com> wrote:
    >
    >
    >>aeuglein wrote:
    >>
    >>
    >>>I have this RegEx:
    >>>/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i
    >>>
    >>>Now, I want to exlude on the end of a String the formats .gif / .jpg /
    >>>.png / .exe / .zip / .rar
    >>>
    >>>How I can this add to my regex ?
    >>
    >>Not being all that great with regex myself, I think this may do the
    >>trick (or at least give you some ideas):
    >>
    >>/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(jpg|gif|png|exe|zip|rar)){0})/i
    >
    >
    > (\.(jpg|gif|png|exe|zip|rar)){0})
    >
    > There's always a zero length match for this; zero occurrences of a pattern is
    > a zero length string, and there's plenty of those in between characters :-)
    heh, I copied out of the wrong file... I wanted to make it into a
    look-ahead (modified from something else I use)... oops

    --
    Justin Koivisto - [email]spam@koivi.com[/email]
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Justin Koivisto Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139