-
-
Save whoami15/6ac1ee187a8d302c4a577b6a349803a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
\Illuminate\Support\Str::macro('extremeSnake', function($value, $delimiter = '_') { | |
$pattern = <<<'REGEXP' | |
/ | |
(?<!^) # don't match the beginning of a string | |
( | |
(?<=[^\p{Lu}])[\p{Lu}\p{M}]+(?=\p{M}?[^\p{Ll}]\p{M}?\p{L}) # string of upper-case (like an abbreviation) | |
| (?<=\p{Lu}{2})[\p{Lu}\p{M}](?=\p{M}?\p{Ll}) # the final upper-case in a sequence | |
| (?<=[^\p{Lu}])[\p{Lu}\p{M}](?=\p{M}?\p{Ll}) # first upper-case in a capitalized sequence | |
) | |
/ux | |
REGEXP; | |
$value = preg_replace($pattern, ' $1', trim($value)); | |
return preg_replace('/[^\p{L}0-9]+/u', $delimiter, Str::lower($value)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment