Description
In this example, the occurrence of every third [0-9]+
will be enclosed in a pair of brackets.
|
| Raw Input
| First number 1, Second 22, Third 333, Fourth 4444,
Fifth 555,
Sixth 66, Seventh 7, Eighth 88,
Ninth 999, Tenth 1010, Eleventh 11111, Twelfth 1212,
Thirteenth 13, Fourteenth 141414, Fifteenth 15
|
|
| Desired Output
| First number 1, Second 22, Third [333], Fourth 4444,
Fifth 555,
Sixth [66], Seventh 7, Eighth 88,
Ninth [999], Tenth 1010, Eleventh 11111, Twelfth [1212],
Thirteenth 13, Fourteenth 141414, Fifteenth [15]
|
|
Script and Comments
Script1 [ 1] s/[0-9]+/\n&/g
[ 2] /\n/!b
[ 3] G
[ 4] :loop
[ 5] s/$/#/
[ 6] s/#{3}$//
[ 7] /\n$/s/\n([0-9]+)/\n[\1]/
[ 8] s/\n//
[ 9] /\n.*\n/b loop
[10] P
[11] s/^.*\n//
[12] h
[13] d
| |