title: Counting regex pattern matches in one line using sed or grep?
body: <p>I want to count the number of matches there is on one single line (or all lines as there always will be only one line).</p>
  
  <p>I want to count not just one match per line as in</p>
  
  <pre><code>echo "123 123 123" | grep -c -E "123" # Result: 1
  </code></pre>
  
  <p>Better example:</p>
  
  <pre><code>echo "1 1 2 2 2 5" | grep -c -E '([^ ])( \1){1}' # Result: 1, expected: 2 or 3
  </code></pre>