Improve compatilbity layer

Better regular expression extraction should avoid weird stack overflows.
This is fix part of #30