Re: match 1, replace 2

*To*: mathgroup at smc.vnet.net*Subject*: [mg56276] Re: match 1, replace 2*From*: Paul Abbott <paul at physics.uwa.edu.au>*Date*: Wed, 20 Apr 2005 05:32:56 -0400 (EDT)*Organization*: The University of Western Australia*References*: <d42khj$3ac$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

In article <d42khj$3ac$1 at smc.vnet.net>, "Trevor Baca" <trevorbaca at gmail.com> wrote: > what rule takes > > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > > to > > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} > > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, -1]? Here is one solution: {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} /. {a__, b_Integer} :> Join[Flatten[({# + 100, -1} & ) /@ {a}], {b}] Cheers, Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul