regex performance improvements, fix #23