Пример #1
0
 public function testReplace()
 {
     $pattern = '#replace this#';
     $regex = new Regex($pattern);
     $text = new Text('This is replace this test');
     $replaced = $regex->replace($text, new Text('a'));
     $this->assertSame('This is a test', $replaced->raw);
 }
Пример #2
0
 public function __construct($raw)
 {
     $regex = new Regex('/^(?:[[:xdigit:]]{2}([-:]))(?:[[:xdigit:]]{2}\\1){4}[[:xdigit:]]{2}$/');
     if (!$regex->check(new Text($raw))) {
         throw new InvalidArgumentException('Expected MAC address, but got [' . var_export($raw, true) . '] instead');
     }
     $this->raw = $raw;
 }
Пример #3
0
 public function __construct($raw)
 {
     $regex = new Regex('/^([a-f0-9]{8})([a-f0-9]{6})([a-f0-9]{4})([a-f0-9]{6})$/');
     $matches = $regex->capture(new Text($raw));
     if (empty($matches)) {
         throw new InvalidArgumentException('Expected MongoDB ID, but got [' . var_export($raw, true) . '] instead');
     }
     list($this->time, $this->machine_id, $this->process_id, $this->counter) = $matches[0];
     $this->raw = $raw;
 }
Пример #4
0
 /**
  * Replaces parts of this Text object based on a search and replace via a regex
  * 
  * @param   Regex  $search   The regex to match
  * @param   Text   $replace  The text with which to replace the found text
  * 
  * @return  Text  A new Text object containing this Text object, with all search text replaced
  */
 public function replaceByRegex(Regex $search, Text $replace)
 {
     return $search->replace($this, $replace);
 }