Re: Regex issue



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


.



Relevant Pages

  • Re: Need a Family of .22LR, 9mm, .45 ACP Pistol for Home Defense
    ... A pattern can be as little as 2" (even as little as .729" right at the ... much greater spreads in a typical home defense scenario. ... For home defense I use a load similar to the old ... rate for conventional shotshell loads when fired from an 18-inch ...
    (rec.guns)
  • Re: Revisiting the Power Explanation
    ... If what you just said is true, then how do you explain nulls in a radiation pattern of an antenna having more ... I use a load. ... internal resistance where the reflected energy is in phase with the ...
    (rec.radio.amateur.antenna)
  • Re: Supreme Court will hear another gun case
    ... Depending on the shot load, roughly 3" to 6", maybe less. ... tricks to open up a pattern, why do you not want to use such a handload ... with BB or similar-size shot at 15 feet. ...
    (rec.crafts.metalworking)
  • Re: mossburg 500
    ... Less recoil=less velocity or lighter ... #load might even pattern better, you won't know until you test it. ... I routinely keep Federal Reduced Recoil 00 buck in my home ...
    (rec.guns)
  • Re: OT: Just Peppered
    ... And tell us Dave, ... And it is very dependent on the gun and the load. ... An article in the 1990 Gun Digest, "The Ring Around Your Pattern" by Don ... to hunt or you will either miss the bird or blow the shit out of it if you ...
    (rec.music.makers.guitar.acoustic)