function encodeIfExists2(unescapedPart, extra) {
  if ('string' == typeof unescapedPart) {
    return encodeURI(unescapedPart).replace(extra, encodeOne);
  }
  return null;
}
if unescapedPart is non null, then escapes any characters in it that aren't
valid characters in a url and also escapes any special characters that
appear in extra.

@param unescapedPart {string}
@param extra {RegExp} a character set of characters in [\01-\177].
@return {string|null} null iff unescapedPart == null.