Creating regular expressions like this, based on user input, is a very bad idea.
https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS