Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: backreferences



On Oct 16,  6:11am, Mikael Magnusson 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.

Minor correction ... (^foo) will be the empty string only if the tested
string begins with "foo".  But then * will consume the "foo", making
the (^foo) useless.  Conversely if the string does not contain "foo" at
all, (^foo) will consume all of it and * will match the empty string.

However, (^foo)(*) could be very useful with backreferences, because
(^foo) puts everything up to "foo" into $match[1], and then (*) puts
from "foo" to the end into $match[2].  Which happens to be a lot like
what Ray was trying to accomplish.

} A useful way to think of (^foo) is a * that will exclude any matches
} that don't match the pattern foo.

Yes.  There's a really long explanation of this in Etc/FAQ 3.27.



Messages sorted by: Reverse Date, Date, Thread, Author