几个有用的正则表达式模版 Regular Expression Patterns( From C# cookbook)

来源:互联网 发布:偏微分方程 知乎 编辑:程序博客网 时间:2024/06/07 04:08
  • 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位数字的分机号码.

 

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 急急急招聘更夫60岁以下 长春招聘更夫 长春一汽大众招聘 长春企业招聘 沈阳上一休一更夫招聘 我愿意我是一个更夫 更始帝 淡极始知花更艳 太始 正始 什么让生活更美好作文400字 诚信让生活更美好六年级500字 科技让生活更美好作文500字 运动让生活更美好500字作文 梦想让生活更美好作文400字 梦想生活更美好作文400字 科技让生活更美好600字 诚信生活更美好作文400字 科技让生活更美好400字 诚信让生活更美好作文400字 运动让生活更美好作文400字 读书让生活更美好作文500字 让生活更美好作文400字 诚信让生活更美好400字作文 阅读让生活更美好作文500字 种花让生活更美好作文600字 运动让生活更美好作文600字 美食让生活更美好500字 阅读让生活更美好作文600字 阅读生活更美好作文600字 诚信让生活更美好作文600字 种花让生活更美好作文400字 诚信生活更美好作文600字 微笑让生活更美好400字 梦想让生活更美好400字 花让生活更美好作文600字 微笑让生活更美好作文600字 爱让生活更美好作文600字 微笑生活更美好作文600字 科技让生活更美好作文600字 科技生活更美好作文600字