src/Str.php
public function pregReplace(
        string $regex,
        string $replacement,
        int $limit = -1
    ): self {
        $value = \preg_replace(
            $regex,
            $replacement,
            $this->value,
            $limit
        );

        if ($value === null) {
            throw new RegexException('', \preg_last_error());
        }

        return new self($value, $this->encoding);
    }
public function pregReplace(
        string $regex,
        string $replacement,
        int $limit = -1
    ): self {
        $value = \preg_replace(
            $regex,
            $replacement,
            $this->value,
            $limit
        );

        if ($value === null) {
            throw new RegexException('', \preg_last_error());
        }

        return new self($value, $this->encoding);
    }
public function pregReplace ( string $ regex , string $ replacement , int $ limit = - 1 ) : self { $ value = \ preg_replace ( $ regex , $ replacement , $ this -> value , $ limit ) ; if ( $ value === null ) { throw new RegexException ( '' , \ preg_last_error ( ) ) ; } return new self ( $ value , $ this -> encoding ) ; }
Replace part of the string by using a regular expression

@param string $regex
@param string $replacement
@param int $limit

@throws Exception If the regex failed

@return self
Replace part of the string by using a regular expression