Allowing users add arbitrary regexes is dangerous (see ReDoS). A good place to start is to create a worker and kill the worker after a timeout (e.g. https://del.dog/ozycymimyz.js).
✋