473,788 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2146
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::Ex plain 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
2087
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 http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800 function fxnParseIt() { var sInputString = 'asp and database';
4
9771
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 numeric value according to an arbitrary regular expression.
7
2619
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) every occurrence of characters "p", "q", "r", "s" with "y". Right now, I do it as follows:
6
4800
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 string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or parentheses. I'd like to use Regex to pull out the words, or the phrases if the words are enclosed in quotes....
17
3980
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 http://forta.com/books/0672325667/
3
2119
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 works, because I used on a vs. script to check. I also believe I foolwed followed the regex syntax for dotnet. here is the source code for the function and testing Public Function regtest(ByVal StringIn As String, ByVal patrn As
6
4857
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 successfully matched. The naive approach is to loop through each regex, and stop when one succeeds. However, I am finding this to be too slow for my application -- currently 30% of the run time is being taken up in the regex matching. I thought...
16
2254
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) pattern search functions. Where performance is an issue you can alway write your own specialized routine of course. However, for the occasional pattern search where performance isn't an issue, would most seasoned .NET developers rely on "Regex" and...
7
2232
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
12213
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 is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements have to be ignored, for exampleI dont want to add links within existing links, or for example link...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.