Forum: Ruby-core Regexp documentation for Regexp::EXTENDED is incomplete

82cdd3a1b7b5642940dbd1f174491fd5?d=identicon&s=25 unknown (Guest)
on 2014-05-03 20:37
(Received via mailing list)
Issue #9801 has been updated by Damon Davison.

I have submitted a pull request on GitHub to make this easier. (Before,
I didn't know I could!)

misc #9801: Regexp documentation for Regexp::EXTENDED is incomplete

* Author: Damon Davison
* Status: Open
* Priority: Normal
* Assignee: Zachary Scott
* Category: doc
* Target version: current: 2.2.0
The documentation for Regexp::EXTENDED, i.e. the `x` flag says that when
it is used, Regexp will ignore all whitespace in the pattern. This is
not completely true.

All whitespace is ignored, except for whitespace which has been escaped
(`\ `) or is within a character class (`[ ]`). Therefore,

/this will not do what you mean/x # this will not work as you expect


/this[ ]will\sdo\ what\s+you\s+mean/x #this will work the same as a
pattern without the Regexp::EXTENDED flag

I found looking at the Perl documentation very useful

regexp-extended-whitespace.rb (261 Bytes)
This topic is locked and can not be replied to.