Question

I have some problem with regular expression for some string cleaning...


I want:

1) if first char is Cyrillic => remove all chars until first number or latin char in string
2) if first char is Latin => save char until first Cyrillic char in string

Part I have with pattern:

$pattern = '/[(\s)(a-zA-Z0-9)(\№)(\_)(\-)(\.)(\/)(\s)(\,)(\')(\")(\*))^(\(\))]*\s/u';

But for the second part, if position of Latin char is middle of input string, I have in output nothing...

Can anybody help me to edit a regexp?

Thanks


For example ($in[must be in result]):


foreach($in as $item){    
    $matches = array();    
    $result = preg_match ($pattern, $item, $matches);    
    print_r($matches);    
} 

$in = array();    
$in[RZL 200 -200] = 'RZL 200 -200 литров, Накопительный электроводонагреватель';    
$in[EKH 50U-] = 'EKH 50U-Вертикальный электроводонагреватель 50 литров';    
$in[EKF 70U,] = 'EKF 70U, Суперплоский электрический водонагреватель -70 литров, Глубина=320 мм';    
$in[FF06 1/2"AA] = 'FF06 1/2"AA фильтр механической очистки ,на холодную воду.';    
$in[FF06 1"AA,] = 'FF06 1"AA, фильтр механической очистки на холодную воду.';    
$in[F76 S 1/2" AA (AB, AC, AD),] = 'F76 S 1/2" AA (AB, AC, AD), фильтр механической очистки , на холодную воду';    
$in[ProfiRoll-2000, 13,3-18,2, 2000] = 'ProfiRoll-2000, 13,3-18,2, 2000 Вт, Телый пол в цементно-песчаную стяжку';    
$in[ProfiMat 160-2,0] = 'ProfiMat 160-2,0 кв.м, 0,320 Вт';    
$in[№203 ,] = 'Набор №203 , Набор фильтрэлементов №203(A560,A-560E,Em,Ecp,A-575E,Em,Ecp)';    
$in[A-575Ep box MAX,] = 'A-575Ep box MAX, Система обратного осмоса, 5 ступеней очистки со встроенным баком, насосом повышения давления и индикатором качества воды, 380 л/сутки (Россия)';    
$in[1500 (] = 'Емкость из ПЭ 1500 (ЕЭЦ1500) л, цилиндрическая вертикальная для питьевой воды';    
$in[HLA-12R-B] = 'Алюминиевый радиатор HLA-12R-B';    
$in[SLH 25/L30 ST] = 'Система обогрева трубопроводов SLH 25/L30 ST';    
$in[FFH 400/12,0] = 'Нагревательный мат FFH 400/12,0';    
$in[AF11S-1A,B,С,D,E,F.] = 'AF11S-1A,B,С,D,E,F.Запасная сетка для F76S,СS,FK76CS и HS10S (от 1/2" до 11/4"), 100,20,50,200,300,500микрон';
$in[A-11 BE (BIG BLUE 10)] = 'Фильтр A-11 BE (BIG BLUE 10) В сборе с кронштейном,ключом и фильтрующим элементом,1 ступень очистки (механическая)';    
$in["TROPIX"] = 'Комплект "TROPIX" МНН-130-1 (1 кв. метр)';
Was it helpful?

Solution

You could perhaps use this regex:

^[^A-Z0-9№_,\/'"*().-]*\s*([A-Z0-9№_,\/'"*(). -]+)

It matches any number of non-latin characters at the beginning of the string, and captures any latin characters when it sees one (or more) just after.

Regex101 demo

Note that there are some cyrillic С which the pattern detects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top