moving the regex matching inside of the C extension