Better unbalanced <ref> handling

Just use a (very) simple regex plus a filter rather than a ridiculously
complicated regex.