This is incorrect, `$` is not a valid python identifier. Here is the official schema:

https://docs.python.org/2/reference/lexical_analysis.html#identifiers

Which means this regex should be more like `/(class|def)\s+([^\d\W]\w*)\s*[\(\:]/mg`