How to find out the number of pattern matched?

Hi all,

I search a pattern in a string. How do I know how many times the pattern
is found/matched?

Thanks,

Li

···

--
Posted via http://www.ruby-forum.com/.

Li Chen wrote:

I search a pattern in a string. How do I know how many times the pattern
is found/matched?

string.scan(pattern).length

HTH,
Sebastian

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Sebastian Hungerecker wrote:

Li Chen wrote:

I search a pattern in a string. How do I know how many times the pattern
is found/matched?

string.scan(pattern).length

HTH,
Sebastian

Thanks,

Li

···

--
Posted via http://www.ruby-forum.com/\.