public function tokenize($str)
    {
        $str = array($str);
        foreach ($this->patterns as $p) {
            if (!is_array($p)) $p = array($p);
            if (count($p)==1) { // split pattern
                $this->split($str, $p[0]);
            } elseif (is_int($p[1])) { // match pattern
                $this->match($str, $p[0], $p[1]);
            } else { // replace pattern
                $this->replace($str, $p[0], $p[1]);
            }
        }

        return $str;
    }