加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式

发布时间:2020-12-13 23:00:16 所属栏目:百科 来源:网络整理
导读:正则表达式: Regex Description Example ^ The start-of-line marker ^tux matches any line that starts with tux $ The end-of-line marker tux$ matches any line that ends with tux . Matches any one character Hack. matches Hack1,Hacki but not Ha

正则表达式:

Regex Description Example
^ The start-of-line marker ^tux matches any line that starts with tux
$ The end-of-line marker tux$ matches any line that ends with tux
. Matches any one character Hack. matches Hack1,Hacki but not Hack12,Hackil; only one additional character matches
[] Matches any one of the character set inside [] coo[kl] matches cook or cool
[^] Exclusion set: the carat negates the set of characters in the square brackets; text matching this set will not be returned as a match 9[^01] matches 92,93 but not 91 and 90
[-] Matches any character within the range specified in [1-5] matches any digits from 1 to 5
? The preceding item must match one or zero times colou?r matches color or colour but not colouur
+ The preceding item must match one or more times Rollno-9+ matches Rollno-99,Rollno-9 but not Rollno-
* The preceding item must match zero or more times co*l matches cl,col,coool
() Creates a substring in the regex match Explained below,in the section “Substring match and back-referencing”
{n} The preceding item must match exactly n times [0-9]{3} matches any three-digit number. This can be expanded as: [0-9][0-9][0-9]
{n,} Minimum number of times that the preceding item should match [0-9]{2,} matches any number that is two digits or more in length
Specifies the minimum and maximum number of times thepreceding item should match matches any number that is between two and five digits in length
| Alternation ― one of the items on either side of | should match Oct (1st|2nd) matches Oct 1st or Oct 2nd
The escape character for escaping any of the special characters given above a.b matches a.b but not ajb. The dot is not interpreted as the special “match any one character” regex shown above,but instead a literal dot (period) ASCII character is sought to be matched. Another example: if you’re searching for the US currency symbol “$”,and not the end-of-line marker,you must precede it with a back-slash,like this: $

http://www.opensourceforu.com/2011/04/sed-explained-part-1/

http://www.regexper.com/


收藏:

匹配一个电子邮箱地址:

[A-Za-z0-9._]+@[A-Za-z0-9._]+.[a-zA-Z]{2,4}

匹配HTTPURL的正则表达式:

http://[a-zA-Z0-9-.]+.[a-zA-Z]{2,4}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读