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

正则表达式中容易误解的地方

发布时间:2020-12-14 00:52:47 所属栏目:百科 来源:网络整理
导读:1. d Any digit D Any character except a digit s “whitespace”: space,tab,carriage return,line feed,or newline S Anything except whitespace w A “word character”: [A-Za-z 0-9_ ] W Any character except a word character 2. /[.]/ =~ "b"
1.
d Any digit
D Any character except a digit
s “whitespace”: space,tab,carriage return,line feed,or newline
S Anything except whitespace
w A “word character”: [A-Za-z 0-9_]
W Any character except a word character


2.
/[.]/ =~ "b"
?→ nil
Within brackets,characters like the dot,plus,and star are not special.




3.
/^[ [=]]+$/ =~ '=]=[='
?→ 0
To include open and close brackets inside ofbrackets,escape them with a backslash. Thisexpression matches any sequence of one or morecharacters,all of which must be either [,],or =.(The two anchors ensure that there are no characters before or after the matching characters.)


4.
caret在[] 中的用法,取反
/[^ab]/ =~ "z"
?→ 0
Putting a caret at the beginning of a characterclass causes the set to contain all characters
except the ones listed.


5.
正则表达式中间,竖线的用法:分成两个正则表达式
/^Fine birds | cows ate.$/ =~
"Fine birds ate seeds."
?→ 0
A vertical bar divides the regular expression intotwo smaller regular expressions. A match means that either the entire left regexp matches or theentire right one does. This regular expression does not mean “Matcheither 'Fine birds ate.' or 'Fine cows ate.'” It actually matches either a string beginning with "Finebirds" or one ending in "cows ate."

(编辑:李大同)

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

    推荐文章
      热点阅读