unusual regex exception

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)
 
F

Fritz

Tim said:
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)
Your are using (), which means to gather all such into a list of expressions
accessible with $expression. You are probably going over an internal limit;
at one time 9 was the limit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top