Ask a Question related to PHP Development, Design and Development.
-
aeuglein #1
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
-
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 -
[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/... -
[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... -
[PHP] regex problem
So ^+/* or ^!(partner/) Merlin wrote: -
[PHP] regex problem
That's if($string == 'test/contact.html') of course... :) it could be if($string == "test/contact.html") -
Justin Koivisto #2
Re: Regex - Problem
aeuglein wrote:
Not being all that great with regex myself, I think this may do the> 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 ?
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
-
Andy Hassall #3
Re: Regex - Problem
On 9 Oct 2003 05:35:23 -0700, [email]sdz@gmx.de[/email] (aeuglein) wrote:
Assuming Perl-compatible regexes due to the use of \w.>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 ?
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
-
Andy Hassall #4
Re: Regex - Problem
On Thu, 09 Oct 2003 15:50:50 GMT, Justin Koivisto <spam@koivi.com> wrote:
(\.(jpg|gif|png|exe|zip|rar)){0})>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
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
-
Justin Koivisto #5
Re: Regex - Problem
Andy Hassall wrote:
heh, I copied out of the wrong file... I wanted to make it into a> 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 :-)
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



Reply With Quote

