分享

Regular Expression Patterns

 windycityboy 2013-09-15
  • Match only alphanumeric characters along with the characters -,+.., and any whitespace: ^([/w/.+-]|/s)*$

   仅包括英文字母(大小写)、数字、"."、"+"、"-"及空格的任意长度的字串

  • Match only alphanumeric characters along with the characters -, +. . and any whitespace, with the stipulation that there is at least one of these characters and no more than 10 of these characters:  ^([/w/.+-]|/s)*{1,10}$

          (同上),但长度为1-10个字符长.

  • Match a person's name, up to 55 characters:   ^[a-zA-Z/'/-/s]{1,55}$

          可以为任意英文字及" ' "、"-"、数字的用户名,长度为1-55个字符长.

  • Match a positive or negative integer:  ^((/+|-)/d)?*$

          可用来表示任意一个正负整数.

  • Match a date in the form ##/##/#### where the day and month can be a one- or two digit value and year can either be a two- or four- digit value: ^/d{1,2}///d{1,2}///d{2,4}$

   日期表达式,其中月日可为一至两位,年份可为两至四位数字. (这个不正确,仅作参考)

  • Match a time to be entered with an optional am or pm extension (note that this regular expression also handles military time): ^/d{1,2}:/d{1,2}/s?{[a|p]m}?$

   带am,pm的时间表达式.(这个不正确,仅作参考)

  • Verify if the input is a social security number of the form ###-##-####:  ^/d{3}-/d{2}-/d{4}$

    校验一串特定格式的编码.

 

    附加一个自已写的,格式为固定以零开始,九位数字分三组,中间可以有"-"  ^0/d{2}-?/d{3}-?/d{3}

  • Match an IPv4 address: ^([0-2]?[0-5]?[0-5]/.){3}[0-2]?[0-5]?[0-5]$

   匹配一个IPv4规则形式的网址.

  • Verify that an email address is in the form name@address where address is not IP address: /w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*

         校验一个邮件地址,其地址为字符形式.(这个不是书上的,比书上的要好)

  • Match or verity a URL that uses either the HTTP, HTTPS, or FTP protocol. Note that this regular expression will not match relative URLs:   ^(http|https|ftp)/://[a-zA-Z0-9/-/.]+/.[a-zA-Z]{2,3}(:[z-aA-Z0-9]*)?/?[a-zA-Z0-9]/-/._/?,/'////+&%/$#/=~])*$

          校验一个URL地址,但这个表达式不能表示相对地址

  • Match only a dollar amount with the optional $and + or - preceding characters(note that any number of decimal places may be added):  ^/$?[+-]?[/d,]*(/./d*)?$

   任意价格表示法(含任意小数位及$符)

 

          This is similar to the previous regular expression except that no more than two decimal places are allowed: ^/$?[+-]? [/d,]*/.?/d{0,2}$

 

          (同上),但最多表示小数点后两位.

  • Match a credit card number to be entered as four sets of four digits separated with a space, - or no character at all:  ^((/d{4}[- ]?){3}/d{4})$

   匹配一个信用卡号,四位一组,中间可以没有,也可能有空格及连字符

  • Match a zip code to be entered as five digits with an optional four-digit extension: ^/d{5}(-/d{4})?$

          匹配邮编形式为5位数字或以连字符与另外4位数字相连. (这个好象不正确,仅供参考)

  • Match a North American phone number with an optional area code and an optional-character to be usecd in the phone number and no extension:  ^(/(?[0-9]{3}/)?)?/-?)[0-9]{3}/-?[0-9]{4}$

    匹配北美电话号码,区号为可选项.

  • Match a phone number similar to the previous regular expression but allow an optional five-digit extension prefixed with either ext or extension:   ^(/(?[0-9]{3}/)?)?/-?)[0-9]{3}/-?[0-9]{4}(/s*ext(ension)?)[0-9]{5})?$

           (同上), 可附加5位数字的分机号码.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多