Tom Allison wrote:
> Generically, how do you impliment the various flags?
> 
> I figured out:  s/  /  /g --> gsub
> and s/  /  /   ->  sub
> 
> What about something like
> /   /ixsmg
> or various combinations thereof?

You can apply modifiers (flags) the same as in Perl: /ixm

  i => insensitive
  x => extended form
  m => dot matches newline (same as Perl's /s flag)

Ruby's default is Perl's /m (ie; ^ and $ match at embedded
lines), if you want to match beginning/end of strings see: \A,
\Z, \z (same meanings as in Perl's regexen).

You may also specify flags within regexen (as in Perl):

  (?imx-imx)             # flags on/off
  (?imx-imx:subpattern)  # flags on/off for subpattern

Finally, you may specify flags by ORing their respective
constants when using Regexp::new (IGNORECASE, EXTENDED, MULTILINE
constants in Regexp)

  Regexp.new('foo', Regexp::IGNORECASE|Regexp::MULTILINE) # => /foo/mi

As you've noticed, Perl's /g (global) flag is just a different
method call in Ruby (#sub == once, #gsub == globally).

Last, but not least, Perl's /e (eval flag) can be achieved using
the block form of #sub or #gsub.

regards,
andrew

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