正则

Posted by Xiaosa's Blog on September 3, 2020
  1. 是否是合法的url
1
2
3
4
values.avatar = values.avatar.replace(/^https?:\/\/[^/]+/, ""); // 如果存在域名 去掉

const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
export const isUrl = path => reg.test(path);