Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: backreferences
On Thu, Oct 15, 2015 at 9:11 PM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> As a sidenote, (^foo)* is always useless to write, since (^foo) will
> expand to the empty string, and then the * will consume anything else.
> A useful way to think of (^foo) is a * that will exclude any matches
> that don't match the pattern foo.
As a recovering Perl addict I cannot +1 this comment enough. Regular
expressions are highly addictive and dangerous. But as Mikael points out it
is extremely easy to write a regexp that is worse than worthless. Google
"regular expression negative lookahead".
Also, Google "now you have two problems". You'll find numerous articles
talking about Jamie Zawinski's observation:
"Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems."
I wholeheartedly agree with that sentiment. Notwithstanding the fact I
still employ regular expressions every single day. The important thing
being that I avoid them outside of ad-hoc interactive searches unless I
have expended considerable thought about their correctness and failure
modes if handed malformed input.
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Messages sorted by:
Reverse Date,
Date,
Thread,
Author