时间:2021-07-01 10:21:17 帮助过:18人阅读
$pi = "/(\w{4})(\d{3})-(\d{4})(\w{2})(\d{1}?)-(2)/x";$phones ="Call555-1212or1-800-555-1212";echo preg_match($pi,$phones)? "1": "2";
$pi = "/(\w{4})(\d{3})-(\d{4})(\w{2})(\d{1}?)-/x";$phones ="Call555-1212or1-800-555-1212";echo preg_match($pi,$phones)? "1": "2";
$pi = "/(\w{4})(\d{3})-(\d{4})(\w{2})(\d{1}?)-/x";
匹配到的是
Array
(
[0] => Call555-1212or1-
[1] => Call
[2] => 555
[3] => 1212
[4] => or
[5] => 1
)
如果加上 (2)
则需要 $phones ="Call555-1212or1- 800-555-1212"; 中套红的位置为 2 才能匹配成功
$pi = "/(\w{4})(\d{3})-(\d{4})(\w{2})(\d{1}?)-/x";
匹配到的是
Array
(
[0] => Call555-1212or1-
[1] => Call
[2] => 555
[3] => 1212
[4] => or
[5] => 1
)
如果加上 (2)
则需要 $phones ="Call555-1212or1- 800-555-1212"; 中套红的位置为 2 才能匹配成功
有点不理解你的意思!
$pi = "/(\w{4})(\d{3})-(\d{4})(\w{2})(\d{1}?)-/x";
匹配到的是
Array
(
[0] => Call555-1212or1-
[1] => Call
[2] => 555
[3] => 1212
[4] => or
[5] => 1
)
如果加上 (2)
则需要 $phones ="Call555-1212or1- 800-555-1212"; 中套红的位置为 2 才能匹配成功
(2)不就是(\d{3})!而且我试过给他命一个名然后调用也不对!只能是位置的问题!但是我找不出原因啊!
(2) 表示匹配字符 2,并可向后引用
如果你想引用 (\d{3}) 则需要写作 \\2
(2) 表示匹配字符 2,并可向后引用
如果你想引用 (\d{3}) 则需要写作 \\2
$pi = "/(\w{4})(?
请问这样写对吗?
(2) 表示匹配字符 2,并可向后引用
如果你想引用 (\d{3}) 则需要写作 \\2
好像还是匹配不了、
不管其他写什么 -2 在你的字串里就肯定没有,-(2)就必然匹配不到