I hope that I understood you correctly.
You can separately store 2 versions of the regular schedule - to check the validity of the entire text and to check the validity of a single character.
If check(string, первое_регулярное_выражение) says that string does not fall under the первое_регулярное_выражение , then do strip(string, второе_регулярное_выражение) , that is, remove those characters that do not fall under it. The second part, by the way, can be optimized, if you do not want to deal with regular expressions for one character.
If you are talking about a more general task - as an arbitrarily taken expression by a finite number of changes, to bring about the appearance of some regexp'а (or report that such a display is impossible) , then this is already a topic for a separate article in the ACM Digital Library .
Here you can try to build some kind of finite state machine or suffix tree and take the Levenshtein distance as a metric, but before doing this, you should look in Google for relevant articles.
The point is that the standard tools for option number 2, presumably, no.