With Saxon, the most important things are
(a) inhibit calls on external Java code, which can be done using Configuration.setAllowExternalFunctions(false)
(b) restrict use of the doc() function by writing a URIResolver which checks for the URIs you want to allow
There's no easy way to restrict the running time of the query at the Saxon level. There may be facilities in the application server or servlet container from which Saxon is run, I'm afraid I don't know. You could write a Saxon TraceListener that monitors the execution time, but it might add significant overhead, and it's not foolproof anyway since the long-running expression might be one that doesn't generate any trace events.
Using regular expressions or other syntactic restrictions on the query text doesn't seem a particularly effective approach to me. The relationship between query complexity and execution time is a very indirect one.
However, you might like to consider restricting the user to use XPath rather than XQuery. That would prevent them doing things like user-defined functions, which pose the risk of infinite recursion.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference