473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2520
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
11
by: jojobar | last post by:
I have a aspx file (snippet shown below): ======= <td class="light-m1" id="rwCompleteButton" runat="server"><br/> <asp:ImageButton CssClass="clear-m1" runat="server" CommandName="Complete"...
13
by: blair.bethwaite | last post by:
Hi all, Does anybody know of a module that allows you to enumerate all the strings a particular regular expression describes? Cheers, -Blair
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
7
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
9
by: Kirk | last post by:
Hi All, the following regular expression matching seems to enter in a infinite loop: ################ import re text = ' MSX INTERNATIONAL HOLDINGS ITALIA srl (di seguito MSX ITALIA) una '...
1
by: python_enthu | last post by:
On Jun 27, 11:05 am, "John Salerno" <johnj...@NOSPAMgmail.comwrote: Thanks John Salerno and John Machin, I am used to perl. So I guess I am better of using re.search instead of re.match BTW,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.