Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>?:</code> means do not capture as part of the matching results (aka <strong>capturing group</strong>), basically ignore the stuff in this set of parenthesis.</p> <p>Example:</p> <pre><code>$matches = array(); $card = '4111123456789012'; if (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $card, $matches)) { var_dump($matches); } echo "\n"; </code></pre> <p>Output:</p> <pre><code>array(2) { [0]=&gt; string(16) "4111123456789012" [1]=&gt; string(3) "012" } </code></pre> <p>vs.</p> <pre><code>$matches = array(); $card = '4111123456789012'; if (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/', $card, $matches)) { var_dump($matches); } echo "\n"; </code></pre> <p>Output:</p> <pre><code>array(1) { [0]=&gt; string(16) "4111123456789012" } </code></pre> <p>Notice in the second example <code>$matches[1]</code> does not exist? That's because you said <code>(?: ...stuff here...)</code> and don't capture it.</p> <p>--</p> <p>In <code>^4[0-9]{12}(?:[0-9]{3})?$</code></p> <p><code>^</code> means the start of the string start matching this pattern.</p> <p><code>4</code> the literal string 4</p> <p><code>[0-9]</code> a single digit of a 0 to 9, inclusive</p> <p><code>{12}</code> is a modifier to the previous character/group. In this case <code>[0-9]{12}</code> means exactly 12 digits</p> <p><code>(?: ... stuff ...)</code> explained above</p> <p><code>?</code> is a modifier to the previous character/group. In this case <code>(...)?</code> zero or 1 of what is in the parenthesis. </p> <p><code>$</code> denotes the end of the matching string.</p> <p>--</p> <p>In <code>^(?:2131|1800|35\d{3})\d{11}$</code></p> <p><code>|</code> denotes OR, so the string can start with 2131, 1800, <strong>OR</strong> 35</p> <p><code>\d</code> is the same as <code>[0-9]</code></p>
 

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