src/SlugGenerator.php
private function replaceWithDelimiter(string $text, string $valid, string $delimiter): string
	{
		$quoted = preg_quote($delimiter);

		// Replace all invalid characters with a single delimiter
		$text = preg_replace(
			'((?:[^'.$valid.']|'.$quoted.')+)us',
			$delimiter,
			$text
		);

		// Remove delimiters from the beginning and the end
		$text = preg_replace('(^(?:'.$quoted.')+|(?:'.$quoted.')+$)us', '', $text);

		return $text;
	}
private function replaceWithDelimiter(string $text, string $valid, string $delimiter): string
	{
		$quoted = preg_quote($delimiter);

		// Replace all invalid characters with a single delimiter
		$text = preg_replace(
			'((?:[^'.$valid.']|'.$quoted.')+)us',
			$delimiter,
			$text
		);

		// Remove delimiters from the beginning and the end
		$text = preg_replace('(^(?:'.$quoted.')+|(?:'.$quoted.')+$)us', '', $text);

		return $text;
	}
private function replaceWithDelimiter ( string $ text , string $ valid , string $ delimiter ) : string { $ quoted = preg_quote ( $ delimiter ) ; // Replace all invalid characters with a single delimiter $ text = preg_replace ( '((?:[^' . $ valid . ']|' . $ quoted . ')+)us' , $ delimiter , $ text ) ; // Remove delimiters from the beginning and the end $ text = preg_replace ( '(^(?:' . $ quoted . ')+|(?:' . $ quoted . ')+$)us' , '' , $ text ) ; return $ text ; }
Replace all invalid characters with a delimiter
and strip the delimiter from the beginning and the end.

@param string $text
@param string $valid
@param string $delimiter

@return string
Replace all invalid characters with a delimiter and strip the delimiter from the beginning and the end .