Add Regex::clearBeginningSlash() and Regex::clearEndingSlash() methods (that remove slash from the beginning and the end of given string)

This commit is contained in:
Meritoo
2019-08-27 20:26:31 +02:00
parent 0afcf9843e
commit e704dacabd
3 changed files with 294 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ class Regex
'color' => '/^[a-f0-9]{6}$/i',
'bundleName' => '/^(([A-Z]{1}[a-z0-9]+)((?2))*)(Bundle)$/',
'binaryValue' => '/[^\x20-\x7E\t\r\n]/',
'beginningSlash' => '|^\/|',
'endingSlash' => '|\/$|',
/*
* Matches:
@@ -999,4 +1001,18 @@ class Regex
return preg_replace('/[-\s]+/', '-', $result);
}
public static function clearBeginningSlash(string $string): string
{
$pattern = static::$patterns['beginningSlash'];
return preg_replace($pattern, '', $string);
}
public static function clearEndingSlash(string $string): string
{
$pattern = static::$patterns['endingSlash'];
return preg_replace($pattern, '', $string);
}
}