Regular tree queries (RTQs) are a class of queries considered especially relevant for the expressiveness and evaluation of XML query languages. The algorithms proposed so far for evaluating queries online, while scanning the input data rather than by explicitly building the tree representation of the input beforehand, only cover restricted subsets of RTQs. In contrast, we introduce here an efficient algorithm for the online evaluation of unrestricted RTQs. We prove our algorithm is optimal in the sense that it finds matches at the earliest possible time for the query and the input document at hand. The time complexity of the algorithm is quadratic in the input size in the worst case and linear in many practical cases. Preliminary experimental evaluation of our practical implementation are very encouraging.