Based on https://github.com/jserv/cregex library (BSD 2-Clause "Simplified" License)
