Javascript: regex universal function