in reply to Re^4: This regexp made simpler
in thread This regexp made simpler
I prefer a correct solution that contains some repetition to an incorrect solution any time. There are ways to make .*? work correctly, but they include a certain amount of backtracking control, which makes them harder to maintain.
This is true especially if Z happens not to be just a latter, but a more complicated pattern.
If that's the case, you should use interpolation anyway, and [^Z]+ is to be replaced by (?s:(?!$Z).)+
In general it does make a difference if Z is actually a single character or something else, and if it's something else that should be mentioned in the original question anyway.
Update: added missing quantifier
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: This regexp made simpler
by rovf (Priest) on Apr 26, 2010 at 11:16 UTC | |
by moritz (Cardinal) on Apr 26, 2010 at 11:36 UTC | |
by rovf (Priest) on Apr 26, 2010 at 12:06 UTC | |
by rubasov (Friar) on Apr 26, 2010 at 14:31 UTC |