473,800 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with Regex

Hi,

The following code snippet is causing CPU to max out on my local machine and
production servers. It looks fine on Expresso though.

Regex rgxVideo = new
Regex(@"<embed( \s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s+src=\s*( ""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+ )(""|')?(\s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s*(/\s*>|>\s*</embed>)",
RegexOptions.Ig noreCase);
string strBody = "<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/26757\" width=\"480\" height=\"418\"
scale=\"ShowAll \" loop=\"loop\" menu=\"menu\" wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/19251\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/20202\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/16549\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>";
foreach (Match objMatch in rgxVideo.Matche s(strBody)) // loop
indefinitely here
{
}

TIA

Jul 31 '08 #1
4 2305
Hello Danny,

I've found Expresso doesn't work well enough for .Net regex. Use the regex
designer at http://www.radsoftware.com.au/ it's free. Check it with that.
Hi,

The following code snippet is causing CPU to max out on my local
machine and production servers. It looks fine on Expresso though.

Regex rgxVideo = new
Regex(@"<embed( \s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s+src=\s*
(""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+ )(""|')?(\s+[a-z]+\s*
=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s*(/\s*>|>\s*</embed>)",
RegexOptions.Ig noreCase);
string strBody = "<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/26757\" width=\"480\" height=\"418\"
scale=\"ShowAll \" loop=\"loop\" menu=\"menu\" wmode=\"Window\ "
quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/19251\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/20202\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/16549\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>";
foreach (Match objMatch in rgxVideo.Matche s(strBody)) //
loop
indefinitely here
{
}

TIA

Jul 31 '08 #2
Hello Danny,

I've found Expresso doesn't work well enough for .Net regex. Use the regex
designer at http://www.radsoftware.com.au/ it's free. Check it with that.
Hi,

The following code snippet is causing CPU to max out on my local
machine and production servers. It looks fine on Expresso though.

Regex rgxVideo = new
Regex(@"<embed( \s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s+src=\s*
(""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+ )(""|')?(\s+[a-z]+\s*
=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s*(/\s*>|>\s*</embed>)",
RegexOptions.Ig noreCase);
string strBody = "<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/26757\" width=\"480\" height=\"418\"
scale=\"ShowAll \" loop=\"loop\" menu=\"menu\" wmode=\"Window\ "
quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/19251\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/20202\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/16549\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>";
foreach (Match objMatch in rgxVideo.Matche s(strBody)) //
loop
indefinitely here
{
}

TIA

Jul 31 '08 #3
Danny,

I tried this in Expresso and it predicts the same behavior you should see in
code, namely that the execution time of your regex grows exponentially with
the size of the input string. I'm guessing that when you tested it in
Expresso, you used a shorter input string or one that easily found a match,
thereofe it terminated quickly. The example in your code does not have a
match (for example, "g4tv" will never match). The regex engine has to try
every possible permutation of your regex hunting for a match. The number of
permutations grows exponentially with the size of the string, so your
application hangs, while it continues to try new permutations. There are
dangerous things in your regex design that cause this. Be very careful with
nested quantifiers, especially when applied to wildcards, like (.*)*. Things
like this can cause the execution time to double every time a single
character is added to the input text. It may work fine for 100 characters,
but add 10 more and the execution time goes up by a factor of 1000, or add 20
characters (a 20% increase in length) and the times goes up by one million
times.

JWT

P.S. I don't know what the Colorado Kid is talking about. Expresso is
specifically designed to work with .NET regex.

"Danny Ni" wrote:
Hi,

The following code snippet is causing CPU to max out on my local machine and
production servers. It looks fine on Expresso though.

Regex rgxVideo = new
Regex(@"<embed( \s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s+src=\s*( ""|')?http://www.g4tv.com/i?sv3?/(?<videokey>\d+ )(""|')?(\s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s*(/\s*>|>\s*</embed>)",
RegexOptions.Ig noreCase);
string strBody = "<embed name=\"VideoPla yer\"
src=\"http://localhost/lv3/26757\" width=\"480\" height=\"418\"
scale=\"ShowAll \" loop=\"loop\" menu=\"menu\" wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/19251\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/20202\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>" +
"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/16549\"
width=\"480\" height=\"418\" scale=\"ShowAll \" loop=\"loop\" menu=\"menu\"
wmode=\"Window\ " quality=\"1\"
type=\"applicat ion/x-shockwave-flash\"></embed>";
foreach (Match objMatch in rgxVideo.Matche s(strBody)) // loop
indefinitely here
{
}

TIA

Aug 1 '08 #4
Kottekoe,

I used to use Expresso for regex testing in my .Net programs, but one day,
something worked in Expresso, but didn't in actual .Net so I ditched it for
the Rad Regex Designer, which is a great tool. I liked Expresso, but find
Rad's better.
Danny,

I tried this in Expresso and it predicts the same behavior you should
see in code, namely that the execution time of your regex grows
exponentially with the size of the input string. I'm guessing that
when you tested it in Expresso, you used a shorter input string or one
that easily found a match, thereofe it terminated quickly. The example
in your code does not have a match (for example, "g4tv" will never
match). The regex engine has to try every possible permutation of your
regex hunting for a match. The number of permutations grows
exponentially with the size of the string, so your application hangs,
while it continues to try new permutations. There are dangerous things
in your regex design that cause this. Be very careful with nested
quantifiers, especially when applied to wildcards, like (.*)*. Things
like this can cause the execution time to double every time a single
character is added to the input text. It may work fine for 100
characters, but add 10 more and the execution time goes up by a factor
of 1000, or add 20 characters (a 20% increase in length) and the times
goes up by one million times.

JWT

P.S. I don't know what the Colorado Kid is talking about. Expresso is
specifically designed to work with .NET regex.

"Danny Ni" wrote:
>Hi,

The following code snippet is causing CPU to max out on my local
machine and production servers. It looks fine on Expresso though.

Regex rgxVideo = new

Regex(@"<embed (\s+[a-z]+\s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s+src=\s
*(""|')?http ://www.g4tv.com/i?sv3?/(?<videokey>\d+ )(""|')?(\s+[a-z]+\
s*=\s*(""[^""]*""|'[^']*'|[^\s]*))*\s*(/\s*>|>\s*</embed>)",

RegexOptions.I gnoreCase);

string strBody = "<embed name=\"VideoPla yer\"

src=\"http://localhost/lv3/26757\" width=\"480\" height=\"418\"

scale=\"ShowAl l\" loop=\"loop\" menu=\"menu\" wmode=\"Window\ "
quality=\"1\ "

type=\"applica tion/x-shockwave-flash\"></embed>" +

"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/19251\"

width=\"480\ " height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\ "

wmode=\"Window \" quality=\"1\"

type=\"applica tion/x-shockwave-flash\"></embed>" +

"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/20202\"

width=\"480\ " height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\ "

wmode=\"Window \" quality=\"1\"

type=\"applica tion/x-shockwave-flash\"></embed>" +

"<embed name=\"VideoPla yer\" src=\"http://localhost/lv3/16549\"

width=\"480\ " height=\"418\" scale=\"ShowAll \" loop=\"loop\"
menu=\"menu\ "

wmode=\"Window \" quality=\"1\"

type=\"applica tion/x-shockwave-flash\"></embed>";

foreach (Match objMatch in rgxVideo.Matche s(strBody)) // loop

indefinitely here

{

}

TIA

Aug 1 '08 #5

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

Similar topics

3
2306
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator id="valValidEmail" runat="server" ControlToValidate="txtEmail" ValidationExpression="^(+)(\.+)*@(+)(\.+)*(\.{2,4})$"
2
1469
by: Luhar | last post by:
After much scouring of information on Regular Expressions from books and the web, I've come up with the this handy little Regex to parse links from HTML: <a\s+href(?:\s+)?=(?:\s+)?+(.?+)+(?:\s+)?>(.*?)</a> It works quite well at extracting the url and title of a link from an anchor tag, with one major problem--if the anchor tag includes other attributes after the HREF= attribute, such as TITLE= or TARGET=, it doesn't consider it a...
2
1954
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a valid IP Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand) txtIPAddress.Focus() Return End If
1
1105
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in VB.Net-
9
2092
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat lot of times here.... Requirement: ------------------- I want to get the value of "href" i.e "city1.html" by searching "city1" between the <a</atag. Please note that "city1" can repeat lot of
7
2590
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward slash then some numbers. For some reason I am not getting that. It won't work at all in 2.0
15
50271
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
3
2412
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I'm trying to learn regex but since I've spent way too much time on the following "simple" case, there's obviously something I'm missing. I need to find all occurrences of a specific non-whitespace character sequence in a string, but only if it occurs somewhere within a set of parentheses and only if it's a whole word. Assuming the sequence to be found is the word "the" and the string to be searched is as follows, the only matches should...
8
1394
by: Alexander Vasilevsky | last post by:
This code Regex ge = new Regex(""); string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_"); returns "8 kBit_s_ 8_000 Hz_ Mono" and I need "8_kBit_s_ 8_000_Hz_ Mono"
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10036
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...
1
7582
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
6815
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
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
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
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.