On Tue, Aug 20, 2013 at 10:31 PM, Dan Shelton <[email protected]> wrote: > I may have found a bug in ~(X). AFAIK the first index (.sh.match[0]) > in .sh.match always lists all patterns for which matches have been > found, and all following indexes (.sh.match[0..inf]) store the > captured matches for a specific bracket pair, right? > > If that's correct, why does '15' appear in .sh.match[0][0] but no > other match has '15' later? > > ksh -c 'x="a15 b2 c3" ; d="${x//~(X)(([[:alnum:]])&([[:digit:]]))+/}" > ; print -v .sh.match' > ( > ( > 15 > 2 > 3 > ) > ( > 5 > 2 > 3 > )
Erm... the issue happens because the + is outside of any bracket pair. That means only the latest match (e.g. the '5') is stored (overwriting previous captured matches of the same bracket pair) while .sh.match[0][0] in your example stores the whole string (and not only the last captured match) which was matched. * Hints: - Use (?:pattern) to turn a bracket pair into a non-capturing bracket pair. It will logicall group stuff together but will not generate an entry in .sh.match - It's usually "wise" to put * and + backtracking stuff inside a bracket pair to prevent brain damage to the programmer... :-) ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) [email protected] \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;) _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
