469,133 Members | 1,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Regular expression in Infinite Loop

Bob
The below regular express can sometimes cause an infinite loop. Anyone know
what could cause this?
string RegexSig = @"To:*\s*(?<address>\S+@\S+)*(\s|\S)*did not reach the
following recipient";

Also shouldn't the framework have some type of loop protection? This will
run forever.

Bob
May 30 '06 #1
1 2244
Bob wrote:
The below regular express can sometimes cause an infinite loop. Anyone know
what could cause this?
string RegexSig = @"To:*\s*(?<address>\S+@\S+)*(\s|\S)*did not reach the
following recipient";


Could you supply a string that causes the regex to go into an infinite
loop? Your regex certainly does match itself (and some trivial
variants) in a finite amount of time.

I don't see anything that looks obviously infinite, but @"(\s|\S)*" is
basically just an expensive way to match @".*" and might take a very
long time in a very long string. (Matching @".*foo" can be optimized -
jump to the end and scan backward for "foo" - in a way that
@"(\s|\S)*foo" almost certainly isn't.)

Beyond that, I suspect you want @"To:?", not @"To:*", and you probably
want to handle addresses like "To: Fred Opper <fr**@opper.net>".

--

..NET 2.0 for Delphi Programmers <http://www.midnightbeach.com/.net>

Delphi skills make .NET easy to learn
Being printed - in stores by June
May 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by Gremlin | last post: by
13 posts views Thread by blair.bethwaite | last post: by
25 posts views Thread by Mike | last post: by
44 posts views Thread by James Watt | last post: by
9 posts views Thread by Kirk | last post: by
1 post views Thread by python_enthu | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.