search: reduce code duplication for regex handling

Signed-off-by: Christopher Larson <chris_larson@mentor.com>