Improve regex library, fixes, add unit tests