473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex.Matches Problem

I am currently working on a project and need to get a return… even if that
return is a failure. I must also add that I have no control over either the
Regular Expression that will be used or the text file that will be parsed,
and while my text example is XML, there is no guarantee that the text file
will be xml.

This is a portion of the file I am testing with:
<Stock ticker="ACEGX" type="EQUITY" title="VAN KAMPEN STRATEGIC GROWTH
FUND CLASS A" price="44.47" net="-0.01" volume="0" />
<Stock ticker="ACSRX" type="EQUITY" title="VAN KAMPEN COMSTOCK FUND CL R"
price="19.85" net="0.02" volume="0" />
<Stock ticker="ADP" type="EQUITY" title="Automati c Data Processing Inc."
price="50.58" net="-0.11" volume="422600" />
<Stock ticker="AEE" type="EQUITY" title="Ameren Corp." price="53.26"
net="-0.41" volume="129800" />
<Stock ticker="AEP" type="EQUITY" title="American Electric Power Company
Inc." price="45.56" net="-0.39" volume="753100" />

Everything works as it should if I use the Regular Expression:
Stock ticker="(?<tick er>.*?)" type="(?<type>. *?)" title="(?<title >.*?)"
price="(?<price >.*?)" net="(?<net>.*? )" volume="(?<volu me>.*?)"

But if I miss 1 space (“net=” instead of “ net=”) there is no return, it
locks up (I let it run all night, it’s not just slow)… (The bad expression):
Stock ticker="(?<tick er>.*?)" type="(?<type>. *?)" title="(?<title >.*?)"
price="(?<price >.*?)"net="(?<n et>.*?)" volume="(?<volu me>.*?)"

I need a way to set up the Regex that will not lock up…

Any ideas?

(If this is not the right place to post this question, please let me know
which forum would be better)
Feb 21 '07 #1
5 1330
Hello JAul,

I'm wondering what exactly your question is. As I understand you, you have
one expression that works and one that doesn't. The one that doesn't work,
also locks up the system for an unknown reason - why do you care, as it
doesn't work anyway?
>But if I miss 1 space (“net=” instead of “ net=”) there is no
return, it
locks up (I let it run all night, it’s not just slow)… (The bad
expression):
Stock ticker="(?<tick er>.*?)" type="(?<type>. *?)" title="(?<title >.*?)"
price="(?<pric e>.*?)"net="(?< net>.*?)" volume="(?<volu me>.*?)"

I need a way to set up the Regex that will not lock up…
Seems to me as if the answer was "use the one with the right spacing (as
you're likely to do anyway, as the other doesn't even work) and you'll be
fine".

I'm sure I'm somehow missing the point.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 21 '07 #2
Thank you for the reply and sorry I was not clear, but I have no control over
the expression or the document, a user will enter the parsing expression and
point at the document, my application needs to report the matches.

If the expression is way off it works, it reports no matches, which is
correct. The problem is if the expression is close but not quite right.

My question is about setting up the regex call...

Regex m_RegEx = new Regex(m_strExpr ession);
MatchCollection m_Matches = m_RegEx.Matches (m_strTextToPar se);
return m_Matches.Count ;

The problem is the m_Matches = m_RegEx.Matches (m_strTextToPar se); never
returns if the expression (m_strExpressio n) is that tad bit off.

What I need is advice on how to set up the call (C# code) so it will not
lock up, that it will return (even if the return is just a failure).
"Oliver Sturm" wrote:
Hello JAul,

I'm wondering what exactly your question is. As I understand you, you have
one expression that works and one that doesn't. The one that doesn't work,
also locks up the system for an unknown reason - why do you care, as it
doesn't work anyway?
But if I miss 1 space (“net=” instead of “ net=”) there is no
return, it
locks up (I let it run all night, it’s not just slow)… (The bad
expression):
Stock ticker="(?<tick er>.*?)" type="(?<type>. *?)" title="(?<title >.*?)"
price="(?<price >.*?)"net="(?<n et>.*?)" volume="(?<volu me>.*?)"

I need a way to set up the Regex that will not lock up…

Seems to me as if the answer was "use the one with the right spacing (as
you're likely to do anyway, as the other doesn't even work) and you'll be
fine".

I'm sure I'm somehow missing the point.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 21 '07 #3
Hello JAul,
>Thank you for the reply and sorry I was not clear, but I have no control
over
the expression or the document, a user will enter the parsing expression
and
point at the document, my application needs to report the matches.
Right, I understand that.
>If the expression is way off it works, it reports no matches, which is
correct. The problem is if the expression is close but not quite right.
Okay - but you say you're not the one who writes that expression, right?
>My question is about setting up the regex call...
<snip>

You seem to be under the impression that there's something you can do
about the call ("setting it up" - what's that supposed to mean?) that
would influence whether or not the expression works. I don't understand
what you imagine you could do. If the expression is wrong, it's wrong - it
won't work under any circumstances.

Actually I would say that if you have an expression that makes the call to
the Matches() method never return, you've found a bug in the regex
implementation. It would probably be good if you'd report that to
Microsoft. But that won't help you now - there's no trick you can use from
the outside to make that method return if it hangs due to that bug.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 21 '07 #4


"Oliver Sturm" wrote:
Hello JAul,
Thank you for the reply and sorry I was not clear, but I have no control
over
the expression or the document, a user will enter the parsing expression
and
point at the document, my application needs to report the matches.

Right, I understand that.
If the expression is way off it works, it reports no matches, which is
correct. The problem is if the expression is close but not quite right.

Okay - but you say you're not the one who writes that expression, right?
My question is about setting up the regex call...

<snip>

You seem to be under the impression that there's something you can do
about the call ("setting it up" - what's that supposed to mean?) that
would influence whether or not the expression works. I don't understand
what you imagine you could do. If the expression is wrong, it's wrong - it
won't work under any circumstances.

Actually I would say that if you have an expression that makes the call to
the Matches() method never return, you've found a bug in the regex
implementation. It would probably be good if you'd report that to
Microsoft. But that won't help you now - there's no trick you can use from
the outside to make that method return if it hangs due to that bug.
Oliver Sturm
--
http://www.sturmnet.org/blog
Thank you Oliver, that is what I was afraid of... I will report the bug and
see what I get back from Micrsoft.

I was hoping that there was something that could be done with the m_Matches
= Regex.Matches(m _strExp) call that would fix the lack of a return.
Feb 21 '07 #5
JAul wrote:
"Oliver Sturm" wrote:
>Actually I would say that if you have an expression that makes the
call to the Matches() method never return, you've found a bug in the
regex implementation. It would probably be good if you'd report that
to Microsoft. But that won't help you now - there's no trick you can
use from the outside to make that method return if it hangs due to
that bug.

Thank you Oliver, that is what I was afraid of... I will report the
bug and see what I get back from Micrsoft.

I was hoping that there was something that could be done with the
m_Matches = Regex.Matches(m _strExp) call that would fix the lack of a
return.
It may not be a bug - some regexes can take a very long time to process even
though they look simple.

Perhaps you could do a test when the user has entered the regex: start the
regex on some test data in a separate thread and if that thread takes too
long, kill the thread and tell the user to try again.

I have no knowledge of creating/killing threads.

Andrew
Feb 22 '07 #6

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

Similar topics

5
1539
by: Bill Cohagan | last post by:
I'm looking for help with a regular expression question, so my first question is which newsgroup is the best one to post to? Just in case *this* is the best choice, here's the problem: I'm trying to "parse" something that looks like a command line; e.g., op arg1, arg2, ..., argn The individual parts (op, arg1, ...) can be matched with a...
2
1867
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to parse the new language, Delphi/Pascal. Source to the highlighter is avail here: http://www.dreamprojections.com/SyntaxHighlighter/Default.aspx ...
4
9727
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
4
1846
by: Garibaldi | last post by:
Folks, I'm having a bad regex day and can sure use your help, please.. I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with 200~ to the end of the string but before the start of the next 200~. Here's the regex expression and test data: (?ms)^200~(.*?)(?=^200~)
7
2605
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b) every occurrence of characters "p", "q", "r", "s" with "y". Right now, I do it as follows:
17
3956
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
4
3597
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the "LOT:". Source text may contain multiple "SUB: ... LOT:" blocks. For example this is my source text:
7
2050
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title Artist - Title (Remix) Artist - Title
1
12161
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements...
0
7839
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...
0
8338
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...
0
8215
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...
0
6610
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
0
5390
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...
0
3836
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...
1
2345
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
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.