感想:
正则表达式,xpath,css感觉是一路货。都是用了,看了,就懂;过后不用就忘的那一类。
What Regular Expressions Are Exactly - Terminology
一、最简单的正则匹配,字符匹配(literal characters)
Twelve characters have special meanings in regular expressions: the backslash
\, the caret ^, the dollar sign $, the period or dot
., the vertical bar or pipe symbol |, the question mark
?, the asterisk or star *, the plus sign
+, the opening parenthesis (, the closing parenthesis
), the opening square bracket [, and the opening curly brace
{. These special characters are often called "metacharacters".
二、元字符
表1.常用的元字符 | |
代码 |
说明 |
.( period or dot) |
匹配除换行符以外的任意字符 |
\w |
匹配字母或数字或下划线或汉字 |
\s |
匹配任意的空白符 |
\d |
匹配数字 |
\b |
匹配单词的开始或结束 |
^(caret) |
匹配字符串的开始 |
$(dollar ) |
匹配字符串的结束 |
\(backslash) |
转义符 |
|(vertical bar or pipe symbo) |
选择符 |
?( question mark) |
零次或一次重复 |
*(asterisk or star) |
零次或多次重复 |
+(plus sign) |
一次或多次重复 |
( opening parenthesis |
定义分组开始,定义断言开始 |
) closing parenthesis |
定义分组结束,定义断言结束 |
[ opening square bracket |
集合定义,如[a-z][aeiou][a|e] |
{ opening curly brace |
指定重复次数定义, 如:{2}重复2次; {2,}重复2次或多次 {2,5}重复2次到5次 |