Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You tagged <code>preg-match</code>, so we'll assume PHP and PCRE. This is fairly easy using <code>([\d,]+)</code> capture groups:</p> <pre><code>/([\d,]+)\s+people\s+.*24 hours,\s+([\d,]+)\s+people.*/sm </code></pre> <ul> <li><code>^</code> = start of the string (removed after comments)</li> <li><code>([\d,]+)</code> the string of digits and commas that make up the first number, captured in <code>()</code></li> <li><code>.+?</code> Non-greed set of any characters following the number up until...</li> <li><code>hours,</code> : ...the literal string hours followed by a comma</li> <li><code>([\d,]+)</code> = Another <code>()</code> capture group for the second number</li> <li><code>.*</code> = Everything else up to the end of the string.</li> <li><code>/sm</code> The multi-line modifier and <code>s</code> "dotall" which makes the <code>.</code> match newlines</li> </ul> <p>Note that this <em>doesn't</em> validate that the number is actually a real number, with the <code>,</code> thousands separator in the right place. It just looks for a string of digits and commas. So even something invalid like <code>99,,112345,</code> would match in that position. But if you don't expect your input to look like that, and <em>do</em> expect a <em>real</em> number to appear at the start of the string and after <code>hours,</code> this isn't a big deal.</p> <p>To match a <em>valid</em> number you would need something more complex like</p> <pre><code>((?:\d{1,3},)(?:\d{3},)*(?:\d{1,3})) </code></pre> <p>And that still isn't even totally right, as it would match 123,456,1.</p> <h3>Quick test in PHP:</h3> <pre><code>$pattern = '/([\d,]+)\s+people\s+.*24 hours,\s+([\d,]+)\s+people.*/sm'; preg_match($pattern, $string, $matches); print_r($matches); Array ( [0] =&gt; 8,222,865 people have bought the game. &lt;/p&gt; &lt;p&gt; In the last 24 hours, 7,087 people bought the game. &lt;/p&gt; [1] =&gt; 8,222,865 [2] =&gt; 7,087 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload