473,804 Members | 3,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression 100% cpu - please help

I have an expression that when run uses 100% cpu for over 1minute.
I can change the expression so this does not happen, but couldsome one explain why this happens so that I don't do it again
expression -->
Departing:</td>.*?</span>(?<departi ngAirportName>. *?)\(
(?<airportCode> \w+)\).*?<li>
(?<departingCit y>[\w\s]+),\s*
(?<departingCou ntry>[\w\s]+).*?
(?<departingTim eHours>\d+):
(?<departingTim eMins>\d+).*?Ar riving:.*?</span>
(?<arrivalAirpo rtName>.*?)\(
(?<arrivelAirpo rtCode>\w+)\).* ?<li>
(?<arrivalCity>[\w\s]+),\s*
(?<arrivalCount ry>[\w\s]+).*?
(?<arrivalTimeH ours>\d+):
(?<arrivalTimeM ins>\d+).*?href =".*?\(
(?<linkURL>.*?) \).*?>
(?<carrier>[\w\s]+)\(
(?<flightNumber >.*?)\).*?
text to search -->
l10 bb2"><span class="textBold ">Wed 16 March 05</span>, 1stop(s)</td>
</tr>
<tr class="h32 dotsbottom canvas">
<td class="text l10">Duration: </td>
<td class="textBold l10">14h00</td>
</tr>
<tr height="60">
<td class="text l10 t15 vtop">Departing :</td>
<td class="text l10 t15 vtop">
<ul class="list">
<li>
<span class="bold">
</span>
Newcastle Int'l (NCL),</li><li>Newcastl e, United Kingdom
</li>
<li>
<span class="bold">12 :05</span> Wed
</li>
</ul>
</td>
</tr>
<tr height="60">
<td class="text l10 t15 vtop">Arriving: </td>
<td class="text l10 t15 vtop">
<ul class="list">
<li>
<span class="bold">
Terminal 1,
</span>
Heathrow (LHR),</li><li>London, United Kingdom
</li>
<li>
<span class="bold">13 :20</span> Wed
</li>
</ul>
</td>
</tr>
<tr>
<td class="textBold l10 t10 b10 vtop"><imgsrc='/images/en/FE/BE/Tailfin/smBA.gif' alt="tailfin" width="30"heigh t="25" alt="" /></td>
<td class="text l10 t10 b10">
<ul class="list">
<li>
Non-stop
</li>
<li>
<ahref="javascr ipt:popupWithNo Return('/otpbvpl/Jsp/opodo/FlifoInfoServle t?BV_SessionID= @@@@1016786011. 1110564120@@@@& BV_EngineID=ccd eaddediigiijcef ecenhdhhldfnk.0 &locale=en_GB&F LIGHT_NUMBER=13 27&AIRLINE_CODE =BA&B_DATE=2005 03161205', 'opodo', 700, 450)"class="lin k">British Airways (BA 1327) ></a>
</li>
<li>
Airplane type - 320
</li>
<li>
Economy restricted
</li>
<li>
<script type="text/javascript" language="JavaS cript">
// work around for netscape 7.0.1/2 encoded characters in link
var eticketURL ='http://www.opodo.co.uk :80/otpbvpl/Global/Page/logObs_FS.jsp?l ocale=en_GB&Fra meSetRequired=Y es&sLoc=https%3 A%2F%2Fopodouk. custhelp.com%2F cgi-bin%2Fopodouk.c fg%2Fphp%2Fendu ser%2Fstd_alp.p hp%3Fp_prod_lvl 1%3D1%26p_prod_ lvl2%3D30&sURLT ype=RightNow';
document.write( '<ahref="javasc ript:popupWithN oReturn(eticket URL,\\'faq\\',7 50,600)" class="link">e-ticket available ></a>');
</script>
</li>
<li>
</li>
</ul>
</td>
</tr>
<tr class="h32">
<td class="textBold l10 beigeBG dotstop bb2"colspan="2" >Connection:</td>
</tr>
<tr height="152">
<td class="text l10 t10 b10 beigeBG dotsbottom vtop">
<ul class="list">
<li>

</li>
<li>

</li>
<li>

</li>
<li>

</li>
</ul>
</td>
<td class="text l10 t10 b10 beigeBG dotsbottom vtop"width="100 %">
<ul class="list">
<li><span class="bold">13 :20</span> Wed - <spanclass="bol d">14:35</span> Wed</li>
<li>
Change plane
</li>
<li class="pt10">
Stop-over duration: 1h15
</li>
</ul>
</td>
</tr>
<tr height="60">
<td class="text l10 t15 vtop">Departing :</td>
<td class="text l10 t15 vtop">
<ul class="list">
<li>
<span class="bold">
Terminal 1,
</span>
Heathrow (LHR),</li><li>London, United Kingdom
</li>
<li>
<span class="bold">14 :35</span> Wed
</li>
</ul>
</td>
</tr>
<tr height="60">
<td class="text l10 t15 vtop">Arriving: </td>
<td class="text l10 t15 vtop">
<ul class="list">
<li>
<span class="bold">
Terminal 1,
</span>
Narita (NRT),</li><li>Tokyo, Japan
</li>
<li>
<span class="bold">11 :05</span> Thu
</li>
</ul>
</td>
</tr>

<tr>
<td class="textBold l10 t10 b10 vtop"><imgsrc='/images/en/FE/BE/Tailfin/smBA.gif' alt="tailfin" width="30"heigh t="25" alt="" /></td>
<td class="text l10 t10 b10">
<ul class="list">
<li>
Non-stop
</li>
<li>
<ahref="javascr ipt:popupWithNo Return('/otpbvpl/Jsp/opodo/FlifoInfoServle t?BV_SessionID= @@@@1016786011. 1110564120@@@@& BV_EngineID=ccd eaddediigiijcef ecenhdhhldfnk.0 &locale=en_GB&F LIGHT_NUMBER=7& AIRLINE_CODE=BA &B_DATE=2005031 61435', 'opodo', 700, 450)"class="lin k">British Airways (BA 7) ></a>
</li>
<li>
Airplane type - 744

</li>
<li>
World Traveller Plus
</li>
<li>
<script type="text/javascript" language="JavaS cript">
// work around for netscape 7.0.1/2 encoded characters in link
var eticketURL ='http://www.opodo.co.uk :80/otpbvpl/Global/Page/logObs_FS.jsp?l ocale=en_GB&Fra meSetRequired=Y es&sLoc=https%3 A%2F%2Fopodouk. custhelp.com%2F cgi-bin%2Fopodouk.c fg%2Fphp%2Fendu ser%2Fstd_alp.p hp%3Fp_prod_lvl 1%3D1%26p_prod_ lvl2%3D30&sURLT ype=RightNow';
document.write( '<ahref="javasc ript:popupWithN oReturn(eticket URL,\\'faq\\',7 50,600)" class="link">e-ticket available ></a>');
</script>
</li>
<li>
</li>
</ul>
</td>
</tr>

--------------------------------
From: Gareth James

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>OM9NFlkZgka V6dNmUKo5Ag==</Id>
Jul 21 '05 #1
1 1856
"Gareth James via .NET 247" <an*******@dotn et247.com> wrote in
news:ev******** ******@TK2MSFTN GP10.phx.gbl...
I have an expression that when run uses 100% cpu for over 1 minute.
I can change the expression so this does not happen, but could some one
explain why this > happens so that I don't do it again

I just entered your expression and your sample string into expresso, and it
didn't take a second to run it. I guess it takes forever on *other* input
string, am I right? e.g. if the expression can't find a match, right?

I'm not 100% certain, but I think things like this : "(...[\w\s]+).*?" will
make it take forever: The [\w\s]+ part will first attempt to match all
word/space characters that follow (like "United Kingdom"), then ".*?" will
eat up any number of characters until the next subexpression matches. Now,
if any subexpression after this one doesn't match, the regex will have to
backtrack: It'll match "United Kingdo" for [\w\s]+, and try all the
subexpressions after this one again, and so on. Now, if you have more than
one expression of that kind, every possible combination will be tried, which
will take some time...

If you can, don't use ".*" or ".*?" at all, because they often lead to much
more possible combinations than you really want. Use some more suitable
character class if there is one. Also, you can (I think) forbid backtracking
on many of those subexpressions: use a greedy subexpression like
(?>[\w\s]+).
or
(?>Departing:</td>.*?</span>(?<departi ngAirportName>. *?)\()
This way the engine won't look at these subexpressions once it has found a
match for them.

Niki
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2031
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing specialized code instead of an RE is almost always the better solution. Here is why.... RE's are complex. Sure it is one line of code, but it is on hell of a line. Some of my RE remind me of the obfuscated code contest winners, where one line of...
6
2036
by: paulsmith5 | last post by:
Hi, I have the following regular expression to validate a date-time field in European or d/m/y h:m:s format. ^((((31\/(0?|1))|((29|30)\/(0?|1)))\/(1|\d)?\d{2})|(29\/0?2\/(((1|\d)?(0||)|((16||)00))))|(0?|1\d|2)\/((0?)|(1))\/((1|\d)?\d{2})) (20|21|22|23|?\d):?\d:?\d$ I wish to ammend it so that the time or h:m:s part is validated only if supplied (i.e. I wish to make the time part optional). At present if a
3
2051
by: giulio santorini | last post by:
Hi, I would like to build a regular expression that allows only a number with 3 integer the decimals separator and other three decimals. I've build the firt part in this way: ^({1}|{1}{1}|100)$ Now I'am tring to build the second one but... it's quite difficult. Somebody could help me? This is what I've done:
4
5175
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
4
5187
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or adate LIKE "2004.01.10 __:15") .... into something like this: .... where adate LIKE "2004.01.10 __:(30/15)" ...
1
260
by: Gareth James via .NET 247 | last post by:
I have an expression that when run uses 100% cpu for over 1minute. I can change the expression so this does not happen, but couldsome one explain why this happens so that I don't do it again expression --> Departing:</td>.*?</span>(?<departingAirportName>.*?)\( (?<airportCode>\w+)\).*?<li> (?<departingCity>+),\s*
2
3019
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text index on one column, and punctuation in the column was causing some problems down the line. This column is used only for full text indexing, and otherwise ignored. I decided to use the following regular expression to remove all punctuation (actually...
3
3336
by: LordHog | last post by:
Hello all, I am attempting to create a small scripting application to be used during testing. I extract the commands from the script file I was going to tokenize the each line as one of the requirements is there one command per line. I have always wanted to learn Regular Expressions, so I was hoping I might do this using Regular Expressions. For a fair number of the command will have the syntax like Write( 0x123, 0x12, 25, 100 ) <-...
7
4404
by: hellbent4u | last post by:
Hi All, I need a regular expression to be used in an ASP page which would allow a user to enter: 1000 as well as 1,000 i.e. an amount without comma as well as with comma(for example 10,000 or 100,000 etc.)
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.