Improved regex capturing