Last active
October 20, 2016 10:27
-
-
Save maximzasorin/f72c81ec9725e6dcff52f8f410cc2422 to your computer and use it in GitHub Desktop.
Убираем верхний регистр в тексте, все слова в верхнем регистре преобразовываются в слова, начинающиеся с заглавной буквы
This file contains 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
var foobar = 'ТЕКСТ В ВЕРХНЕМ РЕГИСТРЕ ДЛЯ ЗАГОЛОВКА СО СЛОВАМИ «В КАВЫЧКАХ»'; | |
foobar = foobar.replace(/(?![«|"|'|\[|\(])(\S)(\S+?)(?=\s|$)/g, function($0, $1, $2) { | |
return $1 + $2.toLowerCase(); | |
}); | |
foobar; // "Текст В Верхнем Регистре Для Заголовка Со Словами «В Кавычках»" |
This file contains 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 | |
$foobar = 'ТЕКСТ В ВЕРХНЕМ РЕГИСТРЕ ДЛЯ ЗАГОЛОВКА СО СЛОВАМИ «В КАВЫЧКАХ»'; | |
$foobar = preg_replace_callback('/(?![«|"|\'|\[|\(])(\S)(\S+?)(?=\s|$)/u', function($matches) { | |
return $matches[1] . mb_strtolower($matches[2]); | |
}, $foobar); | |
$foobar; // "Текст В Верхнем Регистре Для Заголовка Со Словами «В Кавычках»" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment