Original Post
Consider the following regex: (final)?\s*(abstract)?\s*(public|private|protected)?\s*(static)?\s*function\s*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\(([^\)]*)\)(\s*;)? It is designed to find PHP function declarations. The problem is that it takes minutes to search 4KB of PHP source code. The problem is in the beginning. I'm looking for a sequence of possible modifiers (final, abstract, etc.) that may or may not appear before the function declaration. If I remove them from the regex entirely, it runs instantaneously. So, I've just removed them and manually searched for the modifiers after the simplified regex matched. It's a mess, though... Does anyone know how I could make this work reasonably quickly while still having the regular expression find the modifiers for me? Thanks!