There is a line:

  1. Ivan Ivanov Ivanovich - rendered accommodation services (2-bed two-room Suite, Main place), catering services (Custom menu), medical services (Treatment), services related to the organization of tourist travel; 2. Petrov Petr Petrovich - accommodation services are provided (2-bed two-room Suite, Extra bed), catering services (Custom menu), services related to the organization of tourist travel (without medical services); 3. Semenov Semen Semenovich - medical services (Treatment), services related to the organization of tourist travel (without the provision of accommodation services, food services);

It is necessary with the help of a regular php expression to remove the text between ", services," and ";". That is, you need to get a string like:

  1. Ivan Ivanov Ivanovich - rendered accommodation services (2-seater two-room suite, main place), catering services (Custom menu), medical services (Treatment) 2. Petrov Petr Petrovich - rendered accommodation services (2-seater two-room suite, extra bed ), catering services (Custom menu) 3. Semenov Semen Semenovich - medical services are provided (Treatment)

I am writing this regular season, and only one entry is selected.

/, услуги,[^)]+;/ 

How to make all cases selected in a row? For convenience - link to https://regex101.com/r/VYmAld/1

  • preg_replace tried? Your regular - working (I replaced ) on ; but it worked without it. Only on that site you need to use the g flag, but in PHP it is enough to preg_replace ). Regex101 you even the code itself writes . - Wiktor Stribiżew

1 answer 1

I did this:

 /, услуги,[^;]+;/ 

and turned on the global flag on that site.

In PHP will be:

 $str = '1. Иванов Иван Иванович - оказываются услуги проживания (2-х местный двухкомнатный Люкс, Основное место), услуги питания (Заказное меню), медицинские услуги (Лечение), услуги, связанные с организацией туристического путешествия; 2. Петров Пётр Петрович - оказываются услуги проживания (2-х местный двухкомнатный Люкс, Дополнительное место), услуги питания (Заказное меню), услуги, связанные с организацией туристического путешествия (без оказания медицинских услуг); 3. Семенов Семён Семёнович - оказываются медицинские услуги (Лечение), услуги, связанные с организацией туристического путешествия (без оказания услуг проживания, услуг питания);'; $result = preg_replace('/, услуги,[^;]+;/', '', $str);