Fmdpa Posted December 15, 2010 Share Posted December 15, 2010 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 More sharing options...
ShadowMage Posted December 15, 2010 Share Posted December 15, 2010 Try removing the dot in this section:([a-z0-9_].*?)so you have:([a-z0-9_]*?)The dot matches any character including whitespace. Link to comment Share on other sites More sharing options...
Fmdpa Posted December 16, 2010 Author Share Posted December 16, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.