branchRegex should really be a static final class variable. It's good in general, but here in particular, because the regexp pattern is very complex. I'm not sure how frequently this function is called, but still, it's good to parse the pattern just once.