471,594 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

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 2381
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 XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.