ParallelRegex::match PHP Method

match() public method

Attempts to match all patterns at once against a string.
public match ( string $subject, string &$match ) : boolean
$subject string String to match against.
$match string First matched portion of subject.
return boolean True on success.
    public function match($subject, &$match)
    {
        if (count($this->patterns) === 0) {
            return false;
        }
        if (!preg_match($this->getCompoundedRegex(), $subject, $matches)) {
            $match = '';
            return false;
        }
        $match = $matches[0];
        for ($i = 1; $i < count($matches); $i++) {
            if ($matches[$i]) {
                return $this->labels[$i - 1];
            }
        }
        return true;
    }

Usage Example

コード例 #1
0
 function testPatternLabels()
 {
     $regex = new ParallelRegex(false);
     $regex->addPattern("abc", "letter");
     $regex->addPattern("123", "number");
     $this->assertIdentical($regex->match("abcdef", $match), "letter");
     $this->assertEqual($match, "abc");
     $this->assertIdentical($regex->match("0123456789", $match), "number");
     $this->assertEqual($match, "123");
 }
All Usage Examples Of ParallelRegex::match