Pure Prolog regex implementation