Description
Given a line contains several integers
(strings matched [0-9]+),
we want to enclosed with a pair of brackets every integer
except the last one.
|
| Raw Input
| begin 147 next 258 another 3690 final 112358 end
|
|
| Desired Output
| begin [147] next [258] another [3690] final 112358 end
|
|
Script and Comments
Script1 [ 1] s/[0-9]+/\n&/g
[ 2] :loop
[ 3] s/\n([0-9]+)([^\n]+\n)/[\1]\2/g
[ 4] t loop
[ 5] s/\n//
| |
Script2 [ 1] s/[0-9]+/\n&/g
[ 2] s/\n([^\n]*)$/\1/
[ 3] s/\n([0-9]+)/[\1]/g
| |