From: Michael Brooks Date: 2009-09-07T08:00:06+09:00 Subject: Re: How can I do this with regex? Hello Ahmet: I'm not a Ruby guru or anything, I still do most of my coding in Delphi (I love Ruby but it's too slow). However, here are a few hints to help you do what I think your wanting to do (note: each assumes you've filled current_line with a line of text from your Delphi code): 1) Returns true if current_line contains something like " TMyClass = class (TObject)" : -> current_line.match(/=\sclass\b/i) 2) Returns the class name (e.g. TMyClass) from current_line found with the regex from #1: -> current_line.match(/^\s*T(\w*)/) 3) Returns true if the current_line variable starts with and only contains the word "implementation" which will be important for you to know when your about to enter the implementation section: -> current_line.match(/^\s*implementation\s*$/i) 4) You'll need to keep track of the class names you've captured and use a regex in the implementation section to find when you've found a usage of a class. I'll leave that to you to figure out. However, testing for a word (i.e. the class name) on it's own using regex word boundaries with something like this should help: -> current_line.match(/\bTMyClass\b/i) 5) You can use variables (e.g. each class name you're searching for) within a regex by wrapping it in #{} like this: -> current_line.match(/#{myvariable}/) 6) This Ruby feature seems to be very usefull for code parsing, it tells you that you're currently between lines that contains "begin" and "end". -> current_line.match(/begin/i) ... current_line.match(/end/i) 7) Google is your friend; here are a few links (including an online regex evaluator to play with) I found usefull... http://rubular.com/ http://www.rubyxp.com/ http://www.rubyist.net/~slagell/ruby/regexp.html http://codelikezell.com/how-to-use-ruby-variables-in-regular-expressions/ http://www.regular-expressions.info/ruby.html Good Luck, Michael "Ahmet Kilic" wrote in message news:f38b1d0e6f0a0cb4ea4b9d0adf3dcda4@ruby-forum.com... >I want to grep Delphi "class name" and "reference classes" in a delphi > class file. > How can I do that with regex? > > example delphi class like this; > > http://exampledelphi.com/?p=62 > > any idea? > -- > Posted via http://www.ruby-forum.com/.