Jump to content

Match all function names


Fmdpa
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...