From: Suraj Kurapati Date: 2011-11-16T04:46:55+09:00 Subject: [ruby-core:41065] [ruby-trunk - Feature #5588] add negation flag (v) to Regexp Issue #5588 has been updated by Suraj Kurapati. I don't have a use case for the current behavior; it was just the simplest way to remove non-matching input characters that obstructed the matching engine. And I agree with your examples; people would naturally think of /(?v:...)/ as a glorified form of /[^...]/. The solution is to change the parse-tree expansion into this: /(?v:r)/ => /(?:(?:rN)?.)/ In this manner, the /(?:rN)/ acts as a barrier that only allows input characters that *do not* match `r` to be matched by the /./. However, this seems very similar to Tanaka's 2007 solution[1]: /(?v:r)/ => /(?:(?!r).)/ I will play with Oniguruma in GDB some more to learn how (?!) works. Perhaps my OP_NEGATE modification is actually unnecessary. Cheers. [1]: http://www.ruby-forum.com/topic/133413#595368 ---------------------------------------- Feature #5588: add negation flag (v) to Regexp http://redmine.ruby-lang.org/issues/5588 Author: Suraj Kurapati Status: Assigned Priority: Normal Assignee: Yui NARUSE Category: core Target version: 2.0.0 Please add a negation flag (v) to regexps which inverts them: "ruby" =~ /perl/v #=> true (turn on negation) "ruby" !~ /perl/v #=> false (turn on negation) "ruby" =~ /(?v:perl)/ #=> true (turn on negation) "ruby" !~ /(?v:perl)/ #=> false (turn on negation) "ruby" =~ /(?-v:perl)/ #=> false (turn off negation) "ruby" !~ /(?-v:perl)/ #=> true (turn off negation) The flag name "v" comes from the ex(1) command of the same name. This has beneficial applications where it is sometimes difficult to construct what you want to match but much easier to construct what you *do not* want to match. Having this negation built in the regexp itself would remove the need for us to change our Ruby code to process a regexp in a different way. For example, suppose that you are passing a regexp to the `--name` command-line option of MiniTest. This regexp tells MiniTest to only run those tests whose names match. If Ruby had a negation flag on its regexps, then it would be suddenly trivial to make MiniTest skip certain tests by negating the regexp we pass in. In this manner, we get a beneficial feature without ever changing our Ruby code (the codebase of MiniTest in this example). :-) Thanks for your consideration. -- http://redmine.ruby-lang.org