"I'm not back." - Bill Harding, Twister
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"I'm not back." - Bill Harding, Twister
Normal is in the eye of the beholder
"I'm not back." - Bill Harding, Twister
Leslie Chaim, I am impressed by your regexp mastery
Seriously, greedy matching is pretty common, I'm surprised it would be a problem.
And as Leslie would doubtless point out, I'm sure you can get a perfectly good Perl implementation on FreeBSD which will probably be faster than Java for something like this.
Normal is in the eye of the beholder
Yes, I did actually. I made just one mistake: I didn't re-test after surrounding "start" in my lookahead match with spaces! The problem is that the first "start" has already consumed the space which causes the second "start" not to match. Oops. Apologies.Originally posted by Jim Yingst:
Peter - did you test that on Adam's sample pattern? For me it matches "start match1" rather than the desired "match1".
It should, and before I posted I tested that my pattern did match this correctly.Furthermore, what about something like this:
"start foo start bar finish finish"
I'm thinking this should match "bar" only.
No it doesn't? It looks for "start" anywhere inside the matching group!But in your pattern the negative lookahead only looks for a "start" at the beginning of group 1. (And only one "start", which is why it fails the original test input.)
No, been there, tried that, it'll never work because it can match beyond the group you're trying to capture.Passes all tests with flying colours.To make this work as I believe it's supposed to, you'd need to add some wild cards in the lookahead. E.g.
"start ((??!.*start)+.)*?) finish"
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"I'm not back." - Bill Harding, Twister
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|