Pcre remaining

This pr fixes #961 (except for the possible memory leak) and #964.