An important feature of statically typed XML programming languages is the type inference of variables in regular expression patterns, when matching is performed on input of a known type. At least, such an algorithm must be be simple, local, and locally precise. In this paper we investigate the possibility to go beyond local type inference, and propose an algorithm to compute the precise type of the tuple of all variables in a regular expression pattern. Our algorithm relies on notions and algorithms from the factorization theory of regular hedge languages.