ASPN Reg Expressions
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.


paul gibbs

Usually you search for an occurance of a specific word or regexp and then
replace it with something else. I wish to search for a NOT occurance of a
word and then do something.

I thought [^word] is what you use, is this correct.

For example :

objRegExp.Pattern = "<a href=http://([^localhost])//(.*?)>"
strResult = objRegExp.Replace (text,"<a href=//test/$2>")

For all occurances of NOT localhost I want to do something, but for the
occurance of the localhost I want to do nothing.

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Darren Neimke
Tm8sIHRoYXQncyBub3QgcXVpdGUgcmlnaHQuICBXaGVuIHlvdSB3cmFwIGl0ZW1zIGluc2lkZSBv
ZiBbXSB5b3UgY3JlYXRlIGEgY2hhcmFjdGVyIGVudGl0eS4NCiANCklmIEkgY3JlYXRlIHRoZSBm
b2xsb3dpbmcgcGF0dGVybjoNCiANCiAgICBbYmZtdF1hbGwNCiANCkl0IHdpbGwgbWF0Y2ggdGhl
IGZvbGxvd2luZyB3b3JkczoNCiANCiAgICBiYWxsLCBmYWxsLCBtYWxsLCB0YWxsDQogDQpBcyBv
cHBvc2VkIHRvOg0KIA0KICAgIGJmbXRhbGwNCiANClNvIHdoYXQgaGFwcGVucyBpcyB0aGF0IHRo
ZSBlbmdpbmUgYWNjZXB0cyBhbnkgKjEqIG9mIHRoZSBjaGFyYWN0ZXJzIGNvbnRhaW5lZCBpbiB0
aGUgY2hhcmFjdGVyIGVudGl0eS4gIE9mIGNvdXJzZSB0aGUgb3Bwb3NpdGUgYXBwbGllcyB3aGVu
IHlvdSBleGNsdWRlIHRoZW0gYnkgYWRkaW5nIF4gdG8gdGhlIGVudGl0eS4NCiANCllvdXIgcGF0
dGVybjoNCiANCiAgICAiPGEgaHJlZj1odHRwOi8vKCA8aHR0cDovLyg+IFtebG9jYWxob3N0XSkv
LyguKj8pPiINCg0KSXMgYmFzaWNhbGx5IHNheWluZywgZG9uJ3QgbWF0Y2g6DQogDQ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hIE5PVCBvY2N1
cmFuY2Ugb2YgYQ0KCXdvcmQgYW5kIHRoZW4gZG8gc29tZXRoaW5nLg0KCQ0KCUkgdGhvdWdodCBb
XndvcmRdIGlzIHdoYXQgeW91IHVzZSwgaXMgdGhpcyBjb3JyZWN0Lg0KCQ0KCUZvciBleGFtcGxl
IDoNCgkNCglvYmpSZWdFeHAuUGF0dGVybiA9ICI8YSBocmVmPWh0dHA6Ly8oW15sb2NhbGhvc3Rd
KS8vKC4qPyk+Ig0KCXN0clJlc3VsdCA9IG9ialJlZ0V4cC5SZXBsYWNlICh0ZXh0LCI8YSBocmVm
PS8vdGVzdC8kMj4iKQ0KCQ0KCUZvciBhbGwgb2NjdXJhbmNlcyBvZiBOT1QgbG9jYWxob3N0IEkg
d2FudCB0byBkbyBzb21ldGhpbmcsIGJ1dCBmb3IgdGhlDQoJb2NjdXJhbmNlIG9mIHRoZSBsb2Nh
bGhvc3QgSSB3YW50IHRvIGRvIG5vdGhpbmcuDQoJDQoJDQoJDQoJX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18NCglKb2luIHRo
ZSB3b3JsZOKAmXMgbGFyZ2VzdCBlLW1haWwgc2VydmljZSB3aXRoIE1TTiBIb3RtYWlsLg0KCWh0
dHA6Ly93d3cuaG90bWFpbC5jb20NCgkNCgkNCgl8IFthc3BuZ3JlZ2V4cF0gbWVtYmVyIGRhcnJl
bi5uZWlta2VAc2RtLmNvbS5hdSA9IFlPVVIgSUQNCgl8IGh0dHA6Ly93d3cuYXNwbGlzdHMuY29t
L2FzcGxpc3RzL2FzcG5ncmVnZXhwLmFzcCA9IEpPSU4vUVVJVA0KCXwgaHR0cDovL3d3dy5hc3Bs
aXN0cy5jb20vc2VhcmNoID0gU0VBUkNIIEFyY2hpdmVzDQoJDQoJDQoNCg=
Reply to this message...
 
    
Wayne King (ASP.NET)
Use a "negative lookahead assertion". This pattern:

http://(?!localhost)\w+/

will match a string that begins with "http://"; that is not followed by
"localhost", but is followed by one or more word characters; followed by
a "/". Specifically, note that the 'do not match' expression,
"(?!localhost)", is an assertion and as such does not consume any
matched text from the input string. The "\w+" expression that follows
it consumes the text up to the "/".

-Wayne
This posting is provided "AS IS" with no warranties, and confers no
rights.

-----Original Message-----
From: paul gibbs [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 17, 2002 7:41 AM
To: aspngregexp
Subject: [aspngregexp] ASPN Reg Expressions

Usually you search for an occurance of a specific word or regexp and
then=20
replace it with something else. I wish to search for a NOT occurance of
a=20
word and then do something.

I thought [^word] is what you use, is this correct.

For example :

objRegExp.Pattern =3D "<a href=3Dhttp://([^localhost])//(.*?)>"
strResult =3D objRegExp.Replace (text,"<a href=3D//test/$2>")

For all occurances of NOT localhost I want to do something, but for the=20
occurance of the localhost I want to do nothing.

Reply to this message...
 
    
Darren Neimke
Wayne... Is this sort of stuff covered in the Perl books written by
Friedl etc. ? I.e.: are they common to version 5 engines or are they
peculiar to .NET Regular Expression engine?

There's obciously a world of difference between our "old" RegEx engine
and the new .NET engine, as is evidenced by things like "negative
lookahead assertions" etc.

Are there any .NET Reg Ex books on the production line that you're aware
of?

Cheers,
Darren

-----Original Message-----
From: Wayne King (ASP.NET) [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, July 18, 2002 10:47 AM
To: aspngregexp
Subject: [aspngregexp] RE: ASPN Reg Expressions

Use a "negative lookahead assertion". This pattern:

http://(?!localhost)\w+/

will match a string that begins with "http://"; that is not followed by
"localhost", but is followed by one or more word characters; followed by
a "/". Specifically, note that the 'do not match' expression,
"(?!localhost)", is an assertion and as such does not consume any
matched text from the input string. The "\w+" expression that follows
it consumes the text up to the "/".

-Wayne
This posting is provided "AS IS" with no warranties, and confers no
rights.

-----Original Message-----
From: paul gibbs [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 17, 2002 7:41 AM
To: aspngregexp
Subject: [aspngregexp] ASPN Reg Expressions

Usually you search for an occurance of a specific word or regexp and
then=20
replace it with something else. I wish to search for a NOT occurance of
a=20
word and then do something.

I thought [^word] is what you use, is this correct.

For example :

objRegExp.Pattern =3D "<a href=3Dhttp://([^localhost])//(.*?)>"
strResult =3D objRegExp.Replace (text,"<a href=3D//test/$2>")

For all occurances of NOT localhost I want to do something, but for the=20
occurance of the localhost I want to do nothing.

| [aspngregexp] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngregexp.asp" target="_blank">http://www.asplists.com/asplists/aspngregexp.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search" target="_blank">http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Wayne King (ASP.NET)
Yes, the /Mastering Regular Expressions/ book by Mr. Friedl does cover
many of the advanced features like negative lookahead assertion that
were part of Perl 5. However, the .NET regex engine added some new
features that were not part of Perl, and hence are not covered by that
book.

The .NET Framework SDK docs include information about the features and
constructs supported by the .NET regex engine. The docs provide a basic
description, but you'll probably find you'll need to experiment quite a
bit to really understand some of the new features (I do).

I do not know of any books in production. But, I have heard a rumor
that Mr. Friedl may be working on one that covers the features supported
in .NET.

-Wayne

-----Original Message-----
From: Darren Neimke [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 17, 2002 6:26 PM
To: aspngregexp
Subject: [aspngregexp] RE: ASPN Reg Expressions

Wayne... Is this sort of stuff covered in the Perl books written by
Friedl etc. ? I.e.: are they common to version 5 engines or are they
peculiar to .NET Regular Expression engine?

There's obciously a world of difference between our "old" RegEx engine
and the new .NET engine, as is evidenced by things like "negative
lookahead assertions" etc.

Are there any .NET Reg Ex books on the production line that you're aware
of?

Cheers,
Darren

-----Original Message-----
From: Wayne King (ASP.NET) [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, July 18, 2002 10:47 AM
To: aspngregexp
Subject: [aspngregexp] RE: ASPN Reg Expressions

Use a "negative lookahead assertion". This pattern:

http://(?!localhost)\w+/

will match a string that begins with "http://"; that is not followed by
"localhost", but is followed by one or more word characters; followed by
a "/". Specifically, note that the 'do not match' expression,
"(?!localhost)", is an assertion and as such does not consume any
matched text from the input string. The "\w+" expression that follows
it consumes the text up to the "/".

-Wayne
This posting is provided "AS IS" with no warranties, and confers no
rights.

-----Original Message-----
From: paul gibbs [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 17, 2002 7:41 AM
To: aspngregexp
Subject: [aspngregexp] ASPN Reg Expressions

Usually you search for an occurance of a specific word or regexp and
then=20
replace it with something else. I wish to search for a NOT occurance of
a=20
word and then do something.

I thought [^word] is what you use, is this correct.

For example :

objRegExp.Pattern =3D "<a href=3Dhttp://([^localhost])//(.*?)>"
strResult =3D objRegExp.Replace (text,"<a href=3D//test/$2>")

For all occurances of NOT localhost I want to do something, but for the=20
occurance of the localhost I want to do nothing.

Reply to this message...
 
 




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com