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

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."

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...