Shouldn't this be:

    r'(\#.*))$'

As is, it allows arbitrary text.