From: G_ F_ <8si.greg@...> Date: 2009-09-08T02:31:57+09:00 Subject: Re: regular expression NOT operator Phil Cooper-king wrote: [...] > so for constants I search /([A-Z].*?\b)/ This regex is not going to match a constant. It matches any upper-case letter followed by a non-greedy wildcard followed by a word boundary. A constant has to begin with an upper-case letter, possibly followed by mixed-case letters, numbers and underscores ("_"). The following show the problem: The first two are your regex, and the second two show a fix. /([A-Z].*?\b)/ =~ 'noT a constant' # => 2 /([A-Z].*?\b)/ =~ 'a Constant' # => 2 /\b([A-Z]\w*\b)/ =~ 'noT a constant.' # => nil /\b([A-Z]\w*\b)/ =~ 'a Constant.' # => 2 The # => at the end of the line show where the match occurred. The first set shows a non-constant having a false-positive. Regex are extremely powerful, but you have to think out what can go wrong with them. When you are searching you can get false-positives easily. If you are searching and replacing, you can get destroyed content. Also, "?!" is not a NOT operator, it's a negative look-ahead. A match succeeds if the initial condition matches followed by no match. http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html#UN -- Posted via http://www.ruby-forum.com/.