- . --- 代表任何字符
- %a --- 代表任何字母. 即[a-zA-Z]
- %c --- 代表任何的控制字符.
- %d ---代表任何的数字字符. 即[0-9]
- %l --- 代表所有的小写字母. 即[a-z]
- %p --- 代表所有的标点符号字符.
- %s --- 代表所有空格,tab 字符.
- %u --- 代表所有的大写字母. 即[A-Z]
- %w --- 代表所有的字母数字. 即[a-zA-Z0-9]
- %x --- 代表16进制数字.
- %z --- 代表字符值是 0 的字符. 注意:值为0 的字符是无法正常表达的在表达式中,如果你要使用他,请使用 %z .
- %x (x是任何非字母和数字的字符)
- %% 表示 % , %$ 表示 $
- [set] --- 代表一个字符集合. 如果要表达一个范围集合,在范围开始的字符和结尾的字符之间使用 -
- [^set] --- 表达所有不出现在集合内的.
量词:
- * -- 0或多次,贪婪匹配.
- + -- 1或多次,贪婪匹配.
- - -- 0或多次,非贪婪匹配
- ? -- 0或1次匹配.
另外一些用法:
- %n -- n must be a number between 1 and 9. Matches the nth captured substring (see below)
- %bxy -- matches a substring starting with x and ending with y. The substring must also have the same number of x and y.
- ^ -- When at the beginning of a pattern, it forces the pattern to match the beginning of a string
- $ -- When at the end of a pattern, it forces the pattern to match the end of a string
- When ^ or $ is anywhere else in a pattern, it has no special meaning.