From: Tim Hunter Date: 2008-09-02T04:14:40+09:00 Subject: Re: Regex help, anyone? Ryan Lewis wrote: > I'm making a syntax highlighter for ruby and i just need help with a bit > of regex. > > I need to highlight function names ('hlstring') in strings such as: > "def hlstring(lol, help)" > "def hlstring (omg)" > "def hlstring arg, arg" > > Any help is much appreciated. :) Here's my stab at it. ["def hlstring(lol, help)", "def h2string (omg)", "def h3string arg, arg", "def a()", "def a2"].each do |str| m = /def\s+([A-Za-z_]\w*)/.match(str) puts "#{m[1]} begins at #{m.begin(1)} ends at #{m.end(1)}" end -- RMagick: http://rmagick.rubyforge.org/