NicolasLeGland

Today I used the regular expression

Jun 17th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3.     // https://twitter.com/marsroverdriver/status/346776078645342208
  4.     for ($test = 1 << 16; 0 !== $test; --$test)
  5.     {
  6.         $text = '';
  7.         for ($length = rand(8, 10); 0 !== $length; --$length)
  8.         {
  9.             if (0 === rand(0, 1))
  10.             {
  11.                 $text .= 'o';
  12.             }
  13.             else
  14.             {
  15.                 $text .= chr(rand(ord('a'), ord('z')));
  16.             }
  17.         }
  18.         $reference = preg_match('/^[^o][^o]o[^o][^o]o[^o]o[^o][^o]$/', $text);
  19.         $result = preg_match('/^[^o](?:[^o]o[^o]){2}o[^o]{2}$/', $text);
  20.         if ($reference !== $result)
  21.         {
  22.             echo 'Test failed', PHP_EOL, $text, PHP_EOL;
  23.             var_dump($result);
  24.             var_dump($reference);
  25.             die();
  26.         }
  27.     }
  28.     echo 'Test passed', PHP_EOL;
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment