GetOptionKit\ValueType\RegexType::parse PHP Method

parse() public method

public parse ( $value )
    public function parse($value)
    {
        preg_match($this->option, $value, $this->matches);
        return strval($value);
    }

Usage Example

 public function testValidation()
 {
     $regex = new RegexType('#^Test$#');
     $this->assertTrue($regex->test('Test'));
     $this->assertFalse($regex->test('test'));
     $regex->option = '/^([a-z]+)$/';
     $this->assertTrue($regex->test('barfoo'));
     $this->assertFalse($regex->test('foobar234'));
     $ret = $regex->parse('foobar234');
     $this->assertNotNull($ret);
 }