正则表达式中容易误解的地方
2016-11-13 21:04
281 查看
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-z0-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 of brackets, escape them with a backslash. This expression matches any sequence of one or more characters, 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 character class 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 into two smaller regular expressions. A match means that either the entire left regexp matches or the entire right one does.
This regular expression does not mean “Match either 'Fine birds ate.' or 'Fine cows ate.'” It actually matches either a string beginning with "Fine birds" or one ending in "cows ate."
\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-z0-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 of brackets, escape them with a backslash. This expression matches any sequence of one or more characters, 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 character class 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 into two smaller regular expressions. A match means that either the entire left regexp matches or the entire right one does.
This regular expression does not mean “Match either 'Fine birds ate.' or 'Fine cows ate.'” It actually matches either a string beginning with "Fine birds" or one ending in "cows ate."
相关文章推荐
- 使用正则表达式时,容易出错的地方~
- 在java中使用正则表达式注意的地方
- javascript 容易误解的地方
- javascript正则表达式容易被忽略的小问题整理
- Shiro容易误解的地方
- sed 正则表达式sed不明了的地方
- java 中容易误解的地方
- 一个容易犯错的js手机号码验证正则表达式
- 被误解好久的正则表达式之后向引用
- 常用正则表达式----从其它地方找到的资料,整理以便自己查询
- js容易出错的正则表达式
- javascript正则表达式的容易被忽略的小问题
- 深度解析正则表达式exec和match两者使用的异同以及要注意的地方
- 一个查找正则表达式的好地方
- golang http.Redirect()函数容易误解的地方
- C++ Primer 学习笔记与思考_9 表达式中过的那些容易忽略的地方
- STL set 容易引起误解的一个地方
- 那些容易忽略的事4-(正则表达式反向引用\n)
- 一个学习正则表达式的地方
- 正则表达式语法 (转,开发项目一定要看,用到正则表达式的地方很多的)