Groups | Blog | Home
all groups > dotnet clr > june 2004 >

dotnet clr : strange CLR inner exception with regex


Tim Mackey
6/2/2004 3:23:30 PM
hi,
i have a regular expression to identify any valid form of server url, i.e.
http://server or http://www.server.com or http://server:8080 or anything in
between. very occassionally i'm getting an index out of bounds exception
from one of the inner framework methods, when i use Match(). i don't know
what the input is because its in a production environment and all debugging
is turned off.

my code is as follows:
----------------------------
Regex rex = new Regex(@"http\:\/\/([a-zA-z0-9\-]*\.?)*?(\:[0-9]*)??\/",
RegexOptions.IgnoreCase);
Match match = rex.Match(absoluteUrl); // exception happens here
if(match.Success)
return "/" + absoluteUrl.Replace(match.ToString(), ""); // strip out the
absolute part of the entire url, returning the relative url.
-------------------------------


stack trace:
-------------------------------
System.Text.RegularExpressions.RegexInterpreter.Go() at
System.Text.RegularExpressions.RegexRunner.Scan(Regex regex, String text,
Int32 textbeg, Int32 textend, Int32 textstart, Int32 prevlen, Boolean quick)
at
System.Text.RegularExpressions.Regex.Run(Boolean quick, Int32 prevlen,
String input, Int32 beginning, Int32 length, Int32 startat) at
System.Text.RegularExpressions.Regex.Match(String input)
-------------------------------

thanks for any help
tim mackey.

--------------------------
67d0ebfec70e8db3


Tim Mackey
6/6/2004 8:20:26 PM
hi,
posting to myself to bring this to the top...
i have a regular expression and very occassionally i'm getting an index out
of bounds exception from one of the inner framework methods, when i use
Match(). i don't know what the input is because its in a production
environment and all debugging is turned off.

my code is as follows:
----------------------------
Regex rex = new Regex(@"http\:\/\/([a-zA-z0-9\-]*\.?)*?(\:[0-9]*)??\/",
RegexOptions.IgnoreCase);
Match match = rex.Match(absoluteUrl); // exception happens here
if(match.Success)
return "/" + absoluteUrl.Replace(match.ToString(), ""); // strip out the
absolute part of the entire url, returning the relative url.
-------------------------------

[quoted text, click to view]

AddThis Social Bookmark Button