title: Match multiple lines of text with specific format
body: <p>I am sending a few telnet cmds to a device and reading back its result values in a array.</p>
  <p>I need to filter the data, but I'm not sure if <code>preg_split()</code> or <code>preg_match()</code> is better suited.</p>
  <p>After isolating the desired rows of text, I need to store several portions of text in a mysql table -- for each row.</p>
  <p>All the results that need to be stored are formatted like: <code>0/0 x x xx:xx:xx:xx:xx:xx x x x x x</code>.</p>
  <p>Below is the code that I am using, but it's just filtering the first array column.</p>
  <pre><code> $show_pon[0] = &quot;show ont info 1 all&quot;;
   $show_pon[1] = &quot;show ont info 2 all&quot;;
   $show_pon[2] = &quot;show ont info 3 all&quot;;
   $show_pon[3] = &quot;show ont info 4 all&quot;;
   $show_pon[4] = &quot;show ont info 5 all&quot;;
   $show_pon[5] = &quot;show ont info 6 all&quot;;
   $show_pon[6] = &quot;show ont info 7 all&quot;;
   $show_pon[7] = &quot;show ont info 8 all&quot;;
   $show_pon[8] = &quot;show ont info 9 all&quot;;
   $show_pon[9] = &quot;show ont info 10 all&quot;;
   $show_pon[10] = &quot;show ont info 11 all&quot;;
   $show_pon[11] = &quot;show ont info 12 all&quot;;
   $show_pon[12] = &quot;show ont info 13 all&quot;;
   $show_pon[13] = &quot;show ont info 14 all&quot;;
   $show_pon[14] = &quot;show ont info 15 all&quot;;
   $show_pon[15] = &quot;show ont info 16 all&quot;;   
   
   $telnet-&gt;DoCommand($show_pon, $data_response);
   
   $sections = preg_split('/-{50,}\s*\r?\n/s', $data_response);
  </code></pre>
  <p>Its actually sending 16 different cmds.. and the output reply to array $sections</p>
  <p>the output below is..</p>
  <pre><code> Array 
   ( 
   [0] =&gt; show ont info 1 all 
   [1] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [2] =&gt; 0/0 1 1 AC:4E:91:A6:CF:F5 active online success match VILERMINA-. 
   [3] =&gt; Total: 1, online 1 OLT(config-interface-epon-0/0)# show ont info 2 all 
   [4] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [5] =&gt; 0/0 2 1 E0:E8:E6:4E:62:58 active online success match CLOVES-NAV. 
   [6] =&gt; Total: 1, online 1 OLT(config-interface-epon-0/0)# show ont info 3 all 
   [7] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [8] =&gt; 0/0 3 1 E0:67:B3:93:F1:97 active online success match 0/0 3 2 18:C5:8A:B0:19:4F active online success match 
   [9] =&gt; Total: 2, online 2 OLT(config-interface-epon-0/0)# show ont info 4 all 
   [10] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [11] =&gt; 0/0 4 1 E0:67:B3:A6:45:E1 active online success match Jessica-Si. 0/0 4 2 E0:67:B3:7E:20:05 active online success match onu-id-2 0/0 4 3 E0:67:B3:7D:F8:F9 active online success match onu-id-3 0/0 4 4 E0:E8:E6:4E:69:B8 active online success match onu-id-4 
   [12] =&gt; Total: 4, online 4 OLT(config-interface-epon-0/0)# show ont info 5 all 
   [13] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [14] =&gt; 0/0 5 1 C4:70:0B:26:B9:38 active online success match 0/0 5 2 E0:67:B3:88:33:E2 active online success match 0/0 5 3 E0:E8:E6:4E:70:B8 active powerdown initial initial 0/0 5 4 C4:70:0B:26:5C:28 active online success match 0/0 5 5 E0:E8:E6:4E:75:C8 active online success match 0/0 5 6 E0:E8:E6:4E:69:C0 active online success match 0/0 5 7 E0:67:B3:93:EF:D5 active online success match 
   [15] =&gt; Total: 7, online 6 OLT(config-interface-epon-0/0)# show ont info 6 all 
   [16] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [17] =&gt; 0/0 6 1 E0:67:B3:88:3D:57 active online success match 0/0 6 2 E0:E8:E6:4E:71:08 active online success match 0/0 6 3 E0:E8:E6:4E:74:78 active online success match 
   [18] =&gt; Total: 3, online 3 OLT(config-interface-epon-0/0)# show ont info 7 all 
   [19] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [20] =&gt; 0/0 7 1 00:6D:61:59:D8:48 active online success match 0/0 7 2 E0:E8:E6:4E:55:20 active online success match 
   [21] =&gt; Total: 2, online 2 OLT(config-interface-epon-0/0)# show ont info 8 all 
   [22] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [23] =&gt; 0/0 8 1 E0:E8:E6:4E:69:E0 active online success match 0/0 8 2 E0:E8:E6:4E:70:08 active online success match 
   [24] =&gt; Total: 2, online 2 OLT(config-interface-epon-0/0)# show ont info 9 all 
   [25] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [26] =&gt; 0/0 9 1 E0:E8:E6:4E:62:78 active online success match 0/0 9 2 E0:67:B3:A6:58:0F active online success match 0/0 9 3 9C:28:EF:01:AE:99 active online success match 
   [27] =&gt; Total: 3, online 3 OLT(config-interface-epon-0/0)# show ont info 10 all 
   [28] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [29] =&gt; 0/0 10 1 E0:67:B3:35:CE:9B active online success match 0/0 10 2 E0:67:B3:A6:56:71 active online success match 0/0 10 3 E0:67:B3:A6:25:33 active online success match 
   [30] =&gt; Total: 3, online 3 OLT(config-interface-epon-0/0)# show ont info 11 all 
   [31] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [32] =&gt; 0/0 11 1 E0:67:B3:7D:F3:E0 active online success match 
   [33] =&gt; Total: 1, online 1 OLT(config-interface-epon-0/0)# show ont info 12 all 
   [34] =&gt; F/S P ONT MAC Control Run Config Match Desc ID flag state state state 
   [35] =&gt; 0/0 12 1 E0:67:B3:93:F9:11 active online success match 
   [36] =&gt; Total: 1, online 1 OLT(config-interface-epon-0/0)# show ont info 13 all Error: There is no ONT available. OLT(config-interface-epon-0/0)# show ont info 14 all Error: There is no ONT available. OLT(config-interface-epon-0/0)#  show ont info 15 all Error: There is no ONT available. OLT(config-interface-epon-0/0)# show ont info 16 all Error: There is no ONT available. OLT(config-interface-epon-0/0)# OLT(config-interface-epon-0/0)# 
   )
  </code></pre>
  <p>and now i need to filter this arrays, and just extract or store in a different array just the arrays starting with</p>
  <p>0/0 x x xxxxxxxxxx x x x x x</p>
  <p>which basicaly are the cmds replys, which i have requested the 16 cmds which are 16 different ports on the device, and each port replied devices connected on that port  with the data of that device</p>
  <p>0/0 1 1 00:00:00:00:00 xxxxx xxxxx xxxx xxxx xxxx</p>
  <p>and below update the full telnet cmd reply log for better understanding</p>
  <pre><code> OLT(config-interface-epon-0/0)# show ont info 1 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  1  1   AC:4E:91:A6:CF:F5 active    online     success  match     VILERMINA-.
   -----------------------------------------------------------------------------
     Total: 1, online 1
  
   OLT(config-interface-epon-0/0)# show ont info 2 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
   ----------------------------------------------------------------------------
     0/0  2  1   E0:E8:E6:4E:62:58 active    online     success  match     CLOVES-NAV.
   -----------------------------------------------------------------------------
     Total: 1, online 1
  
   OLT(config-interface-epon-0/0)# show ont info 3 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  3  1   E0:67:B3:93:F1:97 active    online     success  match
     0/0  3  2   18:C5:8A:B0:19:4F active    online     success  match
   -----------------------------------------------------------------------------
     Total: 2, online 2
  
   OLT(config-interface-epon-0/0)# show ont info 4 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  4  1   E0:67:B3:A6:45:E1 active    online     success  match     Jessica-Si.
     0/0  4  2   E0:67:B3:7E:20:05 active    online     success  match     onu-id-2
     0/0  4  3   E0:67:B3:7D:F8:F9 active    online     success  match     onu-id-3
     0/0  4  4   E0:E8:E6:4E:69:B8 active    online     success  match     onu-id-4
   -----------------------------------------------------------------------------
     Total: 4, online 4
  
   OLT(config-interface-epon-0/0)# show ont info 5 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  5  1   C4:70:0B:26:B9:38 active    online     success  match
     0/0  5  2   E0:67:B3:88:33:E2 active    online     success  match
     0/0  5  3   E0:E8:E6:4E:70:B8 active    powerdown  initial  initial
     0/0  5  4   C4:70:0B:26:5C:28 active    online     success  match
     0/0  5  5   E0:E8:E6:4E:75:C8 active    online     success  match
     0/0  5  6   E0:E8:E6:4E:69:C0 active    online     success  match
     0/0  5  7   E0:67:B3:93:EF:D5 active    online     success  match
   -----------------------------------------------------------------------------
     Total: 7, online 6
  
   OLT(config-interface-epon-0/0)# show ont info 6 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  6  1   E0:67:B3:88:3D:57 active    online     success  match
     0/0  6  2   E0:E8:E6:4E:71:08 active    online     success  match
     0/0  6  3   E0:E8:E6:4E:74:78 active    online     success  match
   -----------------------------------------------------------------------------
     Total: 3, online 3
  
   OLT(config-interface-epon-0/0)# show ont info 7 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  7  1   00:6D:61:59:D8:48 active    online     success  match
     0/0  7  2   E0:E8:E6:4E:55:20 active    online     success  match
    -----------------------------------------------------------------------------
      Total: 2, online 2
  
   OLT(config-interface-epon-0/0)# show ont info 8 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  8  1   E0:E8:E6:4E:69:E0 active    online     success  match
     0/0  8  2   E0:E8:E6:4E:70:08 active    online     success  match
   -----------------------------------------------------------------------------
     Total: 2, online 2
  
   OLT(config-interface-epon-0/0)# show ont info 9 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  9  1   E0:E8:E6:4E:62:78 active    online     success  match
     0/0  9  2   E0:67:B3:A6:58:0F active    online     success  match
     0/0  9  3   9C:28:EF:01:AE:99 active    online     success  match
   -----------------------------------------------------------------------------
     Total: 3, online 3
  
   OLT(config-interface-epon-0/0)# show ont info 10 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  10 1   E0:67:B3:35:CE:9B active    online     success  match
     0/0  10 2   E0:67:B3:A6:56:71 active    online     success  match
     0/0  10 3   E0:67:B3:A6:25:33 active    online     success  match
    -----------------------------------------------------------------------------
     Total: 3, online 3
  
   OLT(config-interface-epon-0/0)# show ont info 11 all
    -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  11 1   E0:67:B3:7D:F3:E0 active    online     success  match
   -----------------------------------------------------------------------------
      Total: 1, online 1
  
   OLT(config-interface-epon-0/0)# show ont info 12 all
   -----------------------------------------------------------------------------
     F/S  P  ONT MAC               Control   Run        Config   Match     Desc
             ID                    flag      state      state    state
    ----------------------------------------------------------------------------
     0/0  12 1   E0:67:B3:93:F9:11 active    online     success  match
    -----------------------------------------------------------------------------
     Total: 1, online 1
  
   OLT(config-interface-epon-0/0)# show ont info 13 all
   Error: There is no ONT available.
  
  
   OLT(config-interface-epon-0/0)# show ont info 14 all
   Error: There is no ONT available.
  
  
   OLT(config-interface-epon-0/0)# show ont info 15 all
   Error: There is no ONT available.
  
  
   OLT(config-interface-epon-0/0)# show ont info 16 all
   Error: There is no ONT available.
  </code></pre>