Guard against empty patterns.

Preg match will fill an error log with warnings otherwise.