Jump to content

Match all function names


Fmdpa

Recommended Posts

I'm working on a syntax highlighter. I've got almost everything working except for the function names getting highlighted.

preg_replace('/\b([a-z0-9_].*?)(?=( )?\()/i', '<span class="function_name">$1</span>', $txt);

It works for stand-alone functions such as...

{myfunction} ();

But once you add anything before it, that is matched as well:

{echo myFunction}();

What's wrong with my RegEx?P.S. the curly braces represent the matched area.

Link to comment
Share on other sites

Thanks! That fixed it. Often, when writing regular expressions, I get stuck in a rut thinking one particular thing is wrong. In this case, I was thinking something was wrong with the lookahead/lookbehind assertions, when it really was just a simple little metacharacter causing the problems.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...