diff --git a/Makefile b/Makefile
index 1ad68ed..575f31b 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ LIB = \
 	util/ealloc.o    \
 	util/enmasse.o   \
 	util/eprintf.o   \
+	util/eregcomp.o  \
 	util/estrtod.o   \
 	util/estrtol.o   \
 	util/fnck.o      \
diff --git a/util.h b/util.h
index e438357..0b94152 100644
--- a/util.h
+++ b/util.h
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <regex.h>
 #include <stddef.h>
 #include <sys/types.h>
 #include "arg.h"
@@ -34,6 +35,10 @@ size_t strlcat(char *, const char *, size_t);
 #undef strlcpy
 size_t strlcpy(char *, const char *, size_t);
 
+/* regex */
+int enregcomp(int, regex_t *, const char *, int);
+int eregcomp(regex_t *, const char *, int);
+
 /* misc */
 void enmasse(int, char **, int (*)(const char *, const char *));
 void fnck(const char *, const char *, int (*)(const char *, const char *));
diff --git a/util/eregcomp.c b/util/eregcomp.c
new file mode 100644
index 0000000..49c1bc5
--- /dev/null
+++ b/util/eregcomp.c
@@ -0,0 +1,25 @@
+#include <regex.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#include "../util.h"
+
+int
+enregcomp(int status, regex_t *preg, const char *regex, int cflags)
+{
+    char errbuf[BUFSIZ] = "";
+    int r;
+
+    if((r = regcomp(preg, regex, cflags)) == 0)
+        return r;
+
+    regerror(r, preg, errbuf, sizeof(errbuf));
+    enprintf(status, "invalid regex: %s\n", errbuf);
+    return r;
+}
+
+int
+eregcomp(regex_t *preg, const char *regex, int cflags)
+{
+	return enregcomp(1, preg, regex, cflags);
+}