package io.github.rcarlosdasilva.kits.convention;

/**
 * 正则表达式
 *
 * @author Dean Zhao (rcarlosdasilva@qq.com)
 */
public class PatternProvider {

  /**
   * 国内手机号码:
   * <p>
   * 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[0, 1, 6, 7, 8],
   * 18[0-9]<br>
   * 移动号段:
   * 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188<br>
   * 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186<br>
   * 电信号段: 133,149,153,170,173,177,180,181,189
   */
  public static final String MOBILE = "^1[34578]\\d{9}$";
  /**
   * 固话号码，可包含区号、分机号
   */
  public static final String TELEPHONE = "^((\\(0\\d{2,3}\\)\\s?)|(0\\d{2,3}(\\s-\\s|-)))?\\d{7,8}(-\\d{1,4})?$";
  /**
   * 完整的URI，包含scheme,host,authority,port,path,query,fragment等各部分的绝对地址或相对地址
   */
  public static final String URI_FULL = "^([a-z][a-z0-9+\\-.]*:(//([a-z0-9\\-._~%!$&'()*+,;=]+@)?([a-z0-9\\-" +
      "._~%]+|\\[[a-f0-9:.]+\\]|\\[v[a-f0-9][a-z0-9\\-._~%!$&'()*+,;=:]+\\])(:[0-9]+)?(/[a-z0-9\\-._~%!$&'()*+,;" +
      "=:@]+)*/?|(/?[a-z0-9\\-._~%!$&'()*+,;=:@]+(/[a-z0-9\\-._~%!$&'()*+,;=:@]+)*/?)?)|([a-z0-9\\-._~%!$&'()*+,;=@]+" +
      "(/[a-z0-9\\-._~%!$&'()*+,;=:@]+)*/?|(/[a-z0-9\\-._~%!$&'()*+,;=:@]+)+/?))(\\?[a-z0-9\\-._~%!$&'()*+,;=:@/?]*)?" +
      "(\\#[a-z0-9\\-._~%!$&'()*+,;=:@/?]*)?$";
  /**
   * 相对路径
   */
  public static final String URI_RELATIVE = "^([a-z0-9\\-._~%!$&'()*+,;=@]+(/[a-z0-9\\-._~%!$&'()*+,;=:@]+)*/?|" +
      "(/[a-z0-9\\-._~%!$&'()*+,;=:@]+)+/?)(\\?[a-z0-9\\-._~%!$&'()*+,;=:@/?]*)?(\\#[a-z0-9\\-._~%!$&'()*+,;=:@/?]*)?$";
  /**
   * 域名，只包含scheme,host,authority,port
   */
  public static final String URI_DOMAIN = "^((^[a-z][a-z0-9+\\-.]*:)?//)?([a-z0-9\\-._~%!$&'()*+,;=]+@)?([a-z0-9\\-" +
      "._~%]+|\\[[a-z0-9\\-._~%!$&'()*+,;=:]+\\])$";
  /**
   * 匹配scheme
   */
  public static final String URI_PART_OF_SCHEME = "^([a-z][a-z0-9+\\-.]*):";
  /**
   * 匹配query
   */
  public static final String URI_PART_OF_QUERY = "(?:\\?(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*)?(?:\\#" +
      "(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*)?$";
  /**
   * 邮箱地址
   */
  public static final String EMAIL = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9]" +
      "(?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$";
  /**
   * IPv4地址
   */
  public static final String IPV4 = "^((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|(" +
      "(1\\d{2})|([1-9]?\\d))))$";
  /**
   * IPv6地址
   */
  public static final String IPV6 = "^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}" +
      "(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(" +
      "([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\." +
      "(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|(" +
      "(:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))" +
      "|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:(" +
      "(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:)" +
      "{2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\." +
      "(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|(" +
      "(:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))" +
      "|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\." +
      "(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$";
  /**
   * 用于清除HTML标签
   */
  public static final String HTML_STRIP = "(?s)<(style|script)[^<>]*>.*?</\\1>|</?[a-z][a-z0-9]*[^<>]*>|<!--.*?-->";
  /**
   * 匹配HTML注释
   */
  public static final String HTML_COMMENT = "(?s)<!--.*?-->";
  /**
   * 国内邮编
   */
  public static final String POSTCODE = "^[1-9]\\d{5}$";
  /**
   * 纯数字
   */
  public static final String NUMBER = "^-?\\d+$";
  /**
   * 纯数字
   */
  public static final String NUMBER_DOT = "^-?\\d*\\.\\d+$";

}
