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:

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

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

Ryan L. 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