472,961 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 software developers and data experts.

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!
Jul 17 '05 #1
4 2104
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 - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2
On 9 Oct 2003 05:35:23 -0700, sd*@gmx.de (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 (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #3
On Thu, 09 Oct 2003 15:50:50 GMT, Justin Koivisto <sp**@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 (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #4
Andy Hassall wrote:
On Thu, 09 Oct 2003 15:50:50 GMT, Justin Koivisto <sp**@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 - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
6
by: Talin | last post by:
I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.