Fixes #16 with better regex and adds tests.