正则表达式@符号及其使用方式

The*_*tor 2 php regex

如果在某处我得到了回答,我道歉,我找不到它.这取自preg_match的php参考.

<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
"http://www.php.net/index.html", $matches);
$host = $matches[1];

// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
Run Code Online (Sandbox Code Playgroud)

我理解除了@ ^和@i之外的所有这些.我已经搜索了大量的正则表达式引用,除了作为分隔符之外没有看到@符号的任何提及,这不是这里的情况.

谢谢

Bra*_*tie 5

@正在被用来代替更常见的/因为/在模式中使用.它只是允许模式更易读,而不必逃避它.

想象如下(相同的模式):

@^(?:http://)?([^/]+)@i
/^(?:http:\/\/)?(^\/]+)/i
Run Code Online (Sandbox Code Playgroud)

而且i,正如其他人所说,使图案情况InsEnSAtive.