A
A
Aldadis2021-03-22 11:52:32
MySQL
Aldadis, 2021-03-22 11:52:32

How to separate "stuck together" words in a table?

There is a table prefix_users
The table has a column name
This column contains the names of users of the form:

Коробков Олег Иванович
Горбачевская Юлия Васильевна
Inessa Oliynichenko
Stasenido
Семенова ИринаВикторовна
Иванова ОльгаВикторовна


How can sticky names be separated? It will be enough if I can separate them starting from the register. Those. to
Семенова ИринаВикторовна
turn
Семенова Ирина Викторовна

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AUser0, 2021-03-23
@Aldadis

First check the correctness of the fixes:

SELECT `name`, REGEXP_REPLACE(`name`, '([a-zа-яё])([A-ZА-ЯЁ])', '\\1 \\2', 1, 0, 'c') FROM `prefix_users` WHERE REGEXP_LIKE(`name`, '([a-zа-яё])([A-ZА-ЯЁ])', 'c')

If the test shows the desired result - tooooo ....
UPDATE `prefix_users` SET `name`=REGEXP_REPLACE(`name`, '([a-zа-яё])([A-ZА-ЯЁ])', '\\1 \\2', 1, 0, 'c') WHERE REGEXP_LIKE(`name`, '([a-zа-яё])([A-ZА-ЯЁ])', 'c')

If you only need to share Russian full names, then remove all az and AZ.

S
Slava Rozhnev, 2021-03-22
@rozhnev

If only split by case:

<?php
function split_name($name) {
  return mb_ereg_replace_callback(
    '([а-яa-z])([А-ЯA-Z])',
    function($m) {
      return $m[1] . ' ' . $m[2];
    }, 
    $name
  );
}

echo split_name('Семенова ИринаВикторовна') . PHP_EOL;
echo split_name('Иванова ОльгаВикторовна') . PHP_EOL;
echo split_name('InessaIvanovna Oliynichenko') . PHP_EOL;

share php code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question