T
Tim Mackey
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)
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)