title: How can I split a string into an array in one operation, but only when the line contains a given pattern?
body: <p>I have to match a line in a file and capture the lines contents.
  The line is as as follows:</p>
  
  <pre><code>key:value key:value abc:123
  </code></pre>
  
  <p>I have a block of code processing different lines in the file based on the line content.
  The above line can be identified by the key "abc" being present in the line.
  I need one regex which does the following</p>
  
  <ol>
  <li>Check if "abc" is present in the line </li>
  <li>if "abc" is present get the contents in the form of an array</li>
  </ol>
  
  <p>I am able to do these separately</p>
  
  <pre><code>#gives me an array of the key,value pairs
  array = line.scan(/\w+:\d+/) 
  #matches "abc:value" but does not give me the other keys
  /.*(abc:\d+)/.match(line)
  </code></pre>
  
  <p>Looking for a way do this in one operation</p>