Skip to content

Instantly share code, notes, and snippets.

@maximzasorin
Last active October 20, 2016 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximzasorin/f72c81ec9725e6dcff52f8f410cc2422 to your computer and use it in GitHub Desktop.
Save maximzasorin/f72c81ec9725e6dcff52f8f410cc2422 to your computer and use it in GitHub Desktop.
Убираем верхний регистр в тексте, все слова в верхнем регистре преобразовываются в слова, начинающиеся с заглавной буквы
var foobar = 'ТЕКСТ В ВЕРХНЕМ РЕГИСТРЕ ДЛЯ ЗАГОЛОВКА СО СЛОВАМИ «В КАВЫЧКАХ»';
foobar = foobar.replace(/(?![«|"|'|\[|\(])(\S)(\S+?)(?=\s|$)/g, function($0, $1, $2) {
return $1 + $2.toLowerCase();
});
foobar; // "Текст В Верхнем Регистре Для Заголовка Со Словами «В Кавычках»"
<?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