Why not just use the server.error-handler-404 = "/path/to/index.php"?
But as for the regex itself, you have many unescaped characters in there. The second . I'm assuming you mean as a literal .. If so, you need to escape it with a backslash \.. The same goes with the ? character (which again, I'm assuming you mean a literal ?). So the regex should be:
".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*)?$"
Plus, you could improve it even more by removing the question mark around the query pattern (I prefer this syntax, I find it easier to read):
".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*|)$"