public function addFilter(string $expression): CopyDictionaryJob
    {
        // Check if the first and last char match - if not, we must encapsulate with '/'.
        if ($expression[0] !== substr($expression, -1)) {
            $expression = '/' . $expression . '/';
        }

        // Test if the regex is valid.
        try {
            preg_match($expression, '');
        } catch (\Throwable $error) {
            throw new \InvalidArgumentException(
                sprintf('Filter "%s" is not a valid regular expression - Error: %s', $expression, $error->getMessage()),
                0,
                $error
            );
        }

        $this->filters[] = $expression;

        return $this;
    }
public function addFilter(string $expression): CopyDictionaryJob
    {
        // Check if the first and last char match - if not, we must encapsulate with '/'.
        if ($expression[0] !== substr($expression, -1)) {
            $expression = '/' . $expression . '/';
        }

        // Test if the regex is valid.
        try {
            preg_match($expression, '');
        } catch (\Throwable $error) {
            throw new \InvalidArgumentException(
                sprintf('Filter "%s" is not a valid regular expression - Error: %s', $expression, $error->getMessage()),
                0,
                $error
            );
        }

        $this->filters[] = $expression;

        return $this;
    }
public function addFilter ( string $ expression ) : CopyDictionaryJob { // Check if the first and last char match - if not, we must encapsulate with '/'. if ( $ expression [ 0 ] !== substr ( $ expression , - 1 ) ) { $ expression = '/' . $ expression . '/' ; } // Test if the regex is valid. try { preg_match ( $ expression , '' ) ; } catch ( \ Throwable $ error ) { throw new \ InvalidArgumentException ( sprintf ( 'Filter "%s" is not a valid regular expression - Error: %s' , $ expression , $ error -> getMessage ( ) ) , 0 , $ error ) ; } $ this -> filters [ ] = $ expression ; return $ this ; }
Add a regular expression.

@param string $expression The regular expression matching keys to filter away.

@return CopyDictionaryJob

@throws \InvalidArgumentException When the regex is invalid.
Add a regular expression .