Section 3.11. Using Embedded Options


3.10. Matching a Newline with a Dot

Ordinarily a dot matches any character except a newline. When the m (multiline) modifier is used, a newline will be matched by a dot. The same is true when the Regexp::MULTILINE option is used in creating a regex:

str = "Rubies are red\nAnd violets are blue.\n" pat1 = /red./ pat2 = /red./m str =~ pat1       # nil str =~ pat2       # 11


This multiline mode has no effect on where anchors match (such as ^, $, \A, and \Z); they match in the same places. All that is affected is whether a dot matches a newline.




The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net