[英]PHP regular expression to match pattern \\domain\username
I'm trying to match a string in the format of \\domain\\username using PHP and I can't get it to return the matched pieces in an array. 我正在尝试使用PHP匹配\\ domain \\ username格式的字符串,但是我无法获取它来返回数组中匹配的片段。
$username = "\\domain\jason";
$login = preg_match_all("/^\\\\[a-z0-9\-]+\\[a-z0-9\-]+$/i", $username, $found);
var_dump($found);
array
0 =>
array
empty
I tested my regular expession with an online tester and it matched the string perfectly. 我用一个在线测试仪测试了我的常规实验,它与字符串完全匹配。
You can use this code: 您可以使用以下代码:
$username = "\\domain\jason";
if (preg_match_all('~\\\\?(\w+)~', $username, $arr))
print_r($arr[1]);
Array
(
[0] => domain
[1] => jason
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.