\
general escape character with several uses
^
assert start of subject (or line, in multiline mode)
$
assert end of subject (or line, in multiline mode)
.
match any character except newline (by default)
[
start character class definition
]
end character class definition
¦
start of alternative branch
(
start subpattern
)
end subpattern
?
extends the meaning of (, also 0 or 1 quantifier, also quantifier minimizer
*
0 or more quantifier
+
1 or more quantifier
{
start min/max quantifier
}
end min/max quantifier
\a
alarm, that is, the BEL character (hex 07)
\cx
"control-x", where x is any character
\e
escape (hex 1B)
\f
formfeed (hex 0C)
\n
newline (hex 0A)
\r
carriage return (hex 0D)
\t
tab (hex 09)
\xhh
character with hex code hh
\ddd
character with octal code ddd, or backreference
\d
any decimal digit
\D
any character that is not a decimal digit
\s
any whitespace character
\S
any character that is not a whitespace character
\w
any "word" character
\W
any "non-word" character
\b
word boundary
\B
not a word boundary
\A
start of subject (independent of multiline mode)
\Z
end of subject or newline at end (independent of multiline mode)
\z
end of subject (independent of multiline mode)
疑问:下面这些是什么含义,如何使用?
\b
word boundary
\B
not a word boundary
\A
start of subject (independent of multiline mode)
\Z
end of subject or newline at end (independent of multiline mode)
\z
end of subject (independent of multiline mode)
---------------------------------------------------------------
\b 匹配一个单词边界,也就是指单词和空格间的位置。例如,
’er\b’ 可以匹配"never" 中的 ’er’,但不能匹配 "verb" 中
的 ’er’。
\B 匹配非单词边界。’er\B’ 能匹配 "verb" 中的 ’er’,但不能匹
配 "never" 中的 ’er’。
这是我所知道的。关于你说的另外的3个用法,我没有用过,也没有见人用过,请教一下其他人再^_^
浅妄薄见,望与斟酌
---------------------------------------------------------------
以前没用过,测试结果如下
\A和^的区别
不管有没有multiline, \A都只匹配串的开始位置
而当设了multiline,^ 也匹配 '\n' 或 '\r' 之后的位置
\z\Z和$的区别
不管有没有multiline, \z\Z都只匹配串的结束位置
而当设了multiline,$ 也匹配 '\n' 或 '\r' 之前的位置
\z和\Z的区别
\Z不管最后一行是否是新行,忽略,但\z不忽略
``` A:".preg_replace(" ¦\A1234 ¦m","",$str); echo " ```
``` $:".preg_replace(" ¦1234$ ¦m","",$str); echo " ```
``` Z:".preg_replace(" ¦1234\Z ¦m","",$str); echo " ```
``` z:".preg_replace(" ¦1234\z ¦","",$str); ?>