473,398 Members | 2,343 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,398 software developers and data experts.

Regex issue

I am trying to do a pretty simple pattern match using regex.

The pattern is ^(?:(?<Item>.*?)@:@)*$.

This should return a match for test123@:@ but does not, instead it never
returns when I call Regex.Match, I have to kill the thread.

The code is below, The Regulator (some will know it) returns the correct
results, I cannot work out why.

RegexOptions options = RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline;
Regex matcher = new Regex(@"^(?:(?<Item>.*?)@:@)*$", options);
Match match = matcher.Match(@"test123@:@"); //Never returns from here.

I have tried this on two machines, it just doesnt work.

TIA

JB
Sep 30 '07 #1
2 1529
Hello John,
I am trying to do a pretty simple pattern match using regex.

The pattern is ^(?:(?<Item>.*?)@:@)*$.

This should return a match for test123@:@ but does not, instead it
never returns when I call Regex.Match, I have to kill the thread.

The code is below, The Regulator (some will know it) returns the
correct results, I cannot work out why.

RegexOptions options = RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline; Regex
matcher = new Regex(@"^(?:(?<Item>.*?)@:@)*$", options); Match match =
matcher.Match(@"test123@:@"); //Never returns from here.

I have tried this on two machines, it just doesnt work.

TIA

JB
^(?:(?<Item>.*?)@:@)*$

I'd giess that the problem lies in the last *, but I'm unsure why it would
hang the parser. I've seen these kinds of problems before where a lot of
backtracking is possible.

a better pattern would be: ^(?<item>.*)@:@$

The extra ? after the first .* isn't really needed, unless there are more
than one @:@ signs in your text at the end of a line (which I doubt). But
as you've not sent us the text you're trying to extract your pattern from
I'd have to guess that.

Another pattern that would probably work would be:

^(?<item>[^@]*)@:@$ but in there I assume that @ does not precede the @:@
at all.

I hope this helps. If not, please add some sample input.

Another possible problem might be that your input is simply too large. The
engine isn't very good at reading multiple megabytes of text at once. As
you're looking at the lines one by one, you could use that to your advantage
and load a couple of lines, try to match and load the next couple of lines.
A StringReader would be ideal for that purpose.

--
Jesse Houwing
jesse.houwing at sogeti.nl
Sep 30 '07 #2
In article <46***********************@news.optusnet.com.au> , John B wrote:
This should return a match for test123@:@ but does not, instead it never*
returns when I call Regex.Match, I have to kill the thread.
It sounds as if you are running your code under the debugger. I had what
sounds like the same problem a few weeks ago involving regular expressions
that worked fine using a regex test tool (in my case Expresso). I noticed
that if I set the breakpoint on the line after the match, the breakpoint
was reached. Eventually, I discovered that if the "Autos" window wasn't
open, Visual Studio was able to step though the code including the Match
line.

I suspect that Visual Studio has some problems with some of the objects in
the Match/Regular expression objects. This might be because the VS debugger
actually uses an object's ToString(format,format Provider) to display
values. If the object's ToString() routine takes an exception, it must be
very difficult for the debugger to handle. Any window that shows an
object's value might have the same problem.

Hope this helps.

Mike
Oct 1 '07 #3

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

Similar topics

20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
1
by: rh | last post by:
hi all, take the following 2 c# lines: 1) str = Regex.Replace(str, ".*AAA", ""); 2) str = Regex.Replace(str, "^.*AAA", ""); notice that the only difference is that the pattern in line 2 has a...
1
by: Terry Olsen | last post by:
I download xml logs from several servers every day and read the data out of them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't...
10
by: igor.kulkin | last post by:
I have a small utility program written in Python which works pretty slow so I've decided to implement it in C. I did some benchmarking of Python's code performance. One of the parts of the program...
15
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
1
by: Brian Christensen | last post by:
Came across the following which puzzled me a bit. I havnt been able to find anyting related to the issue so I hope that one in this group might me be able to clarify things for me: When...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
6
by: | last post by:
Hi all, Sorry for the lengthy post but as I learned I should post concise-and-complete code. So the code belows shows that the execution of ValidateAddress consumes a lot of time. In the test...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...
0
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...

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.