Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a very long and convoluted regular expression that fits all your requirements. It will work if your regex engine is based on PCRE (hopefully you're using PHP, Delphi or R..).</p> <pre><code>(?&lt;=[^\d,.]|^)\d{1,3}(,(\d{3}))*((?=[,.](\s|$))|(\.\d+)?(?=[^\d,.]|$)) </code></pre> <p><a href="http://regexr.com?37at5" rel="nofollow">DEMO on RegExr</a></p> <p>The things that make it so long:</p> <ol> <li>Matching multiple numbers on the same line separated by only 1 character (a space) whilst not allowing partial matchs requires a lookahead and a lookbehind.</li> <li>Matching numbers ending with <code>.</code> and <code>,</code> without including the <code>.</code> or <code>,</code> in the match requires another lookahead.</li> </ol> <p><code>(?=[,.](\s|$))</code> <strong>Explanation</strong></p> <p>When writing this explanation I realised the <code>\s</code> needs to be a <code>(\s|$)</code> to match <code>1,</code> at the very end of a string.</p> <p>This part of the regex is for matching the <code>1</code> in <code>1,</code> or the <code>1,000</code> in <code>1,000.</code> so let's say our number is <code>1,000.</code> (with the <code>.</code> on the end).</p> <p>Up to this point the regex has matched <code>1,000</code>, then it can't find another <code>,</code> to repeat the thousands group so it moves on to our <code>(?=[,.](\s|$))</code></p> <p><code>(?=....)</code> means its a lookahead, that means from where we have matched up to, look at whats coming but don't add it to the match.</p> <p>So It checks if there is a <code>,</code> or a <code>.</code> and if there is, it checks that it's immediately followed by whitespace or the end of input. In this case it is, so it'd leave the match as <code>1,000</code></p> <p>Had the lookahead not matched, it would have moved on to trying to match decimal places.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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