Simple question about Ruby Regext

sub/sub! == Find and Replace
gsub/gsub! == Replace All
scan == Find All

James Edward G. II

Thanks! That’s a good chart to keep in my head.

James G. wrote:

On Jan 26, 2007, at 8:45 AM, Peter B. wrote:

Thanks, Wolfgang. So, you suggest the use of “scan” instead of “gsub?”
That would imply the need for a block, which, seems kind of wordy,
but,
it does have power. . . . Thanks again.

gsub/gsub! also take a block.

Which one you use depends mainly on your purpose. Here’s how I view
the methods, in terms of a “Find and Replace” feature set common to
so many programs:

sub/sub! == Find
gsub/gsub! == Find and Replace
scan == Find All

Hope that helps.

James Edward G. II

That does help, James. Thanks. But, don’t “sub” and “sub!” do a
replacement; so, they’re doing more than just finding? At least, they’re
finding and replacing the first instance of whatever, just not globally?