Using regex pre-compilation for better performance
An ugly working version with some bugs