ruiu added a comment. How about defining a copy constructor to llvm::Regex and create mutable copies from const Regexs? Regex seems to be just two-pointer-sized object so copying it should be cheap. https://reviews.llvm.org/D23829