🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #655

Re: Regular Expression mystery

#655
From: Jon Shemitz
Date: Wed, 15 Sep 2004 04:39
29 lines
2068 bytes
John Fowler wrote:

> In the following regex, what does the '/' in [^/] mean and what does the  '?/' at the end of the string mean?
> 
> Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/" etc.


  [^/]+?		At least 1 character besides '/'. 
			As few non-/ as possible.

  (?<port>:\d+)?/	Optionally, a colon followed by a number. 
			Then a mandatory '/'.
 
> Similarly, this Regular Expression is used to replace invalid characters, EXCEPT "." and "@" and "-" but my reading of it is that it replaces (beginning from the left side, as specified by the "^" ) all word-length characters ( the "\w" ) and the "\", ".", "@" and "-" characters as well.
> 
> // Replace invalid characters with empty strings.
>         return Regex.Replace(strIn, @"[^\w\.@-]", "");
> 
> What am I missing?

You're not. This matches anything except alpha-numeric chars, '.',
'@', and '-'. (Try it in
<http://www.midnightbeach.com/dotnet/regexExplorer.html> or any other
regex workbench.)

-- 

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs
Technical Details
Message-ID: <4147C78A.DE1400D5@midnightbeach.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4147c11f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,d9c3806e5dda49d9
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
Message-ID: <4147C78A.DE1400D5@midnightbeach.com>
Date: Tue, 14 Sep 2004 21:39:38 -0700
From: Jon Shemitz <jon@midnightbeach.com>
Reply-To: jon@midnightbeach.com
Organization: Midnight Beach
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
X-Accept-Language: en-US,en
MIME-Version: 1.0
Newsgroups: borland.public.csharpbuilder.language.csharp
Subject: Re: Regular Expression mystery
References: <4147c11f$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 63.249.65.27
X-Trace: newsgroups.borland.com 1095223181 63.249.65.27 (14 Sep 2004 21:39:41 -0700)
Lines: 29
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail