<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>zfyp (zfyp)</title>
    <link>https://ruby-china.org/zfyp</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>如何将匹配的文本块分别存储到数组</title>
      <description>&lt;p&gt;想做一个 apache 的虚拟主机的配置管理脚本。我用正则表达式获取到了需要匹配的块，但是不知道要怎么把匹配的块存放。比如放到数组什么里面&lt;/p&gt;

&lt;p&gt;表达式：
/^[^#]\s*&amp;lt;VirtualHost.*?&amp;gt;[\s\S\n]+&amp;lt;\/VirtualHost&amp;gt;$/&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#&amp;lt;VirtualHost *:80&amp;gt;
#    ServerAdmin webmaster@dummy-host.example.com
#    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
#&amp;lt;/VirtualHost&amp;gt;
Listen *:80
NameVirtualHost *:80
  &amp;lt;VirtualHost   *:80&amp;gt;
          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
  &amp;lt;/VirtualHost&amp;gt;

&amp;lt;VirtualHost   *:80&amp;gt;
          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
  &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;或者看这里 &lt;a href="http://www.rubular.com/r/RWzr1WVmZH" rel="nofollow" target="_blank"&gt;http://www.rubular.com/r/RWzr1WVmZH&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;表达式可以匹配到 www.test1.com、test.com 的区块
但是我要如何才能把匹配的块存到数组？类似下面一样&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["  &amp;lt;VirtualHost   *:80&amp;gt;
          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
  &amp;lt;/VirtualHost&amp;gt;";
"&amp;lt;VirtualHost   *:80&amp;gt;
          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
  &amp;lt;/VirtualHost&amp;gt;"]
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>zfyp</author>
      <pubDate>Fri, 15 Jun 2012 11:25:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/3825</link>
      <guid>https://ruby-china.org/topics/3825</guid>
    </item>
  </channel>
</rss>
