zoukankan      html  css  js  c++  java
  • 几个正则表达式

    1,验证IP地址: Regex regexIP = new Regex(@"^((0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})\.){3}(0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})$");

    2,验证guid: strQuery = Regex.Replace(strTemp, @"(\{[A-Fa-f0-9]{8}(-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}\})+", _guID, RegexOptions.Singleline);

    3,用空格替换/*注释*/: string strQueryTemp2 = Regex.Replace(strQueryTemp1, @"\/\*(\s|.)*?\*\/[;|\s\$+]", "", RegexOptions.Singleline);

    4,用空格替换掉数据库的 --注释 : strQuery = Regex.Replace(strQueryTemp2, @"--[^\n]*", "", RegexOptions.Singleline);

    5,验证端口: Regex regexPort = new Regex(@"^([0-5]?\d?\d?\d?\d|6[0-4]\d\d\d|65[0-4]\d\d|655[0-2]\d|6553[0-5])$");

    6,验证名称只能(中英文数字或-空格):

    (1):!Regex.IsMatch(this.Name.Text.Trim(), "^[ |\u4e00-\u9fa5a-zA-Z0-9|-]+$") ||

    (2):Regex.IsMatch(this.Name.Text.Trim(), "^[\u3040-\u309F\u30A0-\u30FF]") ||

    (3):Name.Text.Length != Name.Text.Trim().Length

    7,验证域名:

    !Regex.IsMatch(this.txtDomainName.Text.Trim(), "^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$") ||
    this.txtDomainName.Text.Length != this.txtDomainName.Text.Trim().Length

  • 相关阅读:
    自动化运维-ansible
    Linux中安装wget命令
    Celery
    SQLAlchemy
    非关系型数据库--MongoDB
    Flask框架
    Redis
    公钥与私钥
    win10 文件扩展名的更改
    if 和 elif 的区别
  • 原文地址:https://www.cnblogs.com/tangtang615/p/1420808.html
Copyright © 2011-2022 走看看