Regex help, anyone?

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. :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

"def foo(bar, baz)".scan(/def (\w+)/) => => [["foo"]]

···

On Tue Sep 2 01:54:42 2008, 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

--
Fred O. Phillips

BBC7 7572 755F 83E0 3209 504A E4F7 874F 1545 9D41

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. :slight_smile:

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/