From: Robert Klemme Date: 2009-08-31T16:37:21+09:00 Subject: Re: Regex: Get Class Name 2009/8/31 Brian Candler : > Ahmet Kilic wrote: >> This a C++ class name, >> const std::string DRAPBase::CLASS_NAME = "DRAPBase"; >> I am writing like this >> classname =  text.scan(/::CLASS_NAME = (.*?)\s+";/) >> but it is not true. > > You're matching `::CLASS_NAME = ' followed by zero or more characters > followed by one or more space characters followed by "; > > It's the "one or more space characters" which doesn't match. Maybe you > meant \S which means non-space character? e.g. > > classname = text.scan /::CLASS_NAME = "(\S+?)";/ I'd probably do /::CLASS_NAME\s*=\s*"([^"]+)"/ Note to OP: (.*?) is a particular awful construction especially with a variable length match pattern afterwards. As long as there is at least one space (.*?) will always match the empty string in this case: irb(main):010:0> 5.times {|i| p /(.*?)\s+/ =~ (" " * i), $1, $&, '---'} nil nil nil "---" 0 "" " " "---" 0 "" " " "---" 0 "" " " "---" 0 "" " " "---" => 5 irb(main):011:0> Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/