On Thu, 7 Dec 2000, Ben Tilly wrote:

> into Ruby.  The code I chose is at:
> 
> http://www.perlmonks.org/index.pl?node_id=34786
> 
[caveat lector: I have not looked at that site]

Based on the discussions about efficiency, I wonder if
this is any use to you.

#!/usr/local/bin/ruby

string = "I am the very model of a modern Major General"

re = /[aeiou]/i

new_string = string.gsub(re) {
 puts $& + " " + $~.pre_match + " " + $~.pre_match.length.to_s
 "*"
}

puts string   # is unchanged
puts new_string


Which gives


I  0
a I  2
e I am th 7
e I am the v 10
o I am the very m 15
e I am the very mod 17
o I am the very model  20
a I am the very model of  23
o I am the very model of a m 26
e I am the very model of a mod 28
a I am the very model of a modern M 33
o I am the very model of a modern Maj 35
e I am the very model of a modern Major G 39
e I am the very model of a modern Major Gen 41
a I am the very model of a modern Major Gener 43
I am the very model of a modern Major General
* *m th* v*ry m*d*l *f * m*d*rn M*j*r G*n*r*l

	Hugh
	hgs / dmu.ac.uk