想做一个 apache 的虚拟主机的配置管理脚本。我用正则表达式获取到了需要匹配的块,但是不知道要怎么把匹配的块存放。比如放到数组什么里面
表达式: /^[^#]\s*<VirtualHost.*?>[\s\S\n]+<\/VirtualHost>$/
#<VirtualHost *:80>
# ServerAdmin [email protected]
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
Listen *:80
NameVirtualHost *:80
<VirtualHost *:80>
DirectoryIndex index.php index.html index.htm
ServerName test.com
DocumentRoot /var/www/html/test.com
ErrorLog logs/test.com-error_log
CustomLog logs/test.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DirectoryIndex index.html index.php index.htm
ServerName www.test1.com
DocumentRoot /var/www/html/test1.com
ErrorLog logs/test1.com-error_log
CustomLog logs/test1.com-access_log common
</VirtualHost>
或者看这里 http://www.rubular.com/r/RWzr1WVmZH
表达式可以匹配到 www.test1.com、test.com 的区块 但是我要如何才能把匹配的块存到数组?类似下面一样
[" <VirtualHost *:80>
DirectoryIndex index.php index.html index.htm
ServerName test.com
DocumentRoot /var/www/html/test.com
ErrorLog logs/test.com-error_log
CustomLog logs/test.com-access_log common
</VirtualHost>";
"<VirtualHost *:80>
DirectoryIndex index.html index.php index.htm
ServerName www.test1.com
DocumentRoot /var/www/html/test1.com
ErrorLog logs/test1.com-error_log
CustomLog logs/test1.com-access_log common
</VirtualHost>"]