Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I'm using ctags on linux to create tags for source code using vim and the Tlist plug-in. The current ctags function parsing for PHP is woeful so i've downloaded the source for ctags and im going to change the regex that parses the functions.

Because i'm dealing with lots of code that has functions declared in many different ways i need a regex to reliably parse the function names properly.

Do you have one you could share that parses a php function name from a line of source code?

This is the current patched and 'improved' one from the ctags source which misses many functions, especially those marked as final or static first.

(^[ \t]*)(public[ \t]+|protected[ \t]+|private[ \t]+)?(static[ \t]+)?function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)
share|improve this question
    
All of your [ \t] should be \s+. public \n function is perfectly valid. – meagar Sep 15 '11 at 21:37
    
It's not mine it's from the source, i'm working to find more robust solution. I'd though i'd ask before writing a monster ;) – Gary Willoughby Sep 15 '11 at 21:41
1  
why dont you just use Reflection? – Gordon Sep 15 '11 at 22:41

2 Answers 2

up vote 1 down vote accepted

Would just adding static and final to the possible list of words to ignore, and making it match more then one of the keywords be close enough?

(^[ \t]*)((public|protected|private|static|final)[ \t]*)*function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)

Would mean it would accept junk like 'public public static final function bogus()', but php's syntax checking will reject it, and therefore shouldn't be a significant issue.

share|improve this answer
s/^.*\sfunction\s([^\(]*)\(.*$/\1/i 

i tested it with some sed

grep -Ri function *| head -10 | sed 's/^.*\sfunction\s\([^\(]*\)(.*$/\1/i'
share|improve this answer
    
you only want function name right? – David Chan Sep 15 '11 at 21:59
    
yeah, just the function name. That's pretty much what i came up with, i think the keywords on the front are just gonna have to be ignored and just check for anything. – Gary Willoughby Sep 15 '11 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.