title: PHP preg_replace multiple replacements
body: <p>I'm fairly weak on regex and this is giving me a headache to try and figure out. I'm just trying to extract the time from the string and modify the text of the time. I get strings in the following forms:</p>
  
  <pre><code>"Some text I don't care about | 2.3 seconds ago"
  "Some text I don't care about | 5.2 minutes ago"
  "Some text I don't care about | 7.0 hours ago"
  "Some text I don't care about | 1.9 days ago"
  </code></pre>
  
  <p>I would like to replace the above strings to they are in the forms respectively:</p>
  
  <pre><code>"2.3 secs"
  "5.2 mins"
  "7.0 hrs"
  "1.9 days"
  </code></pre>
  
  <p>I know basics of replacing in regex, but to remove multiple things in front and behind the text that I want, while replacing "hours" with "hrs", etc is beyond my regex skill level.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Well after messing about I came to a solution using multiple different functions. I don't exactly like it, but it works. I would prefer a single preg_replace solution if possible. Here is my current <em>ugly</em> solution:</p>
  
  <pre><code>$testString = "This is text I don't care about | 7.3 seconds ago";
  $testString = array_shift(array_reverse(explode('|', $testString)));
  $pattern = array('/seconds/', '/minutes/', '/hours/', '/ago/');
  $replace = array('secs', 'mins', 'hrs', '');
  $testString = trim(preg_replace($pattern, $replace, $testString));
  </code></pre>
  
  <p>Output is: <code>7.3 secs</code></p>