I use preg_match() to parse a string, which can have several options:

 1.Черный (black.png) 1.Черный (black.png) Черный (black.png) 1.Черный 1.Черный Черный 

It is necessary that where the indicated value is returned: 1) a digit to the point (if there is a digit with a dot) 2) after a dot to the parenthesis (if there is or until the end of the line) 3) what is in the round brackets (if there is)

I managed to read variants without values ​​in parentheses:

 /(^\d+)?\.?\s+?(.*)/u 

Please tell me the options or help advice.

    1 answer 1

    You can build on the next option.

     $text = '1.Черный (black.png)'; $text = ' 1.Черный (black.png)'; $text = 'Черный (black.png)'; $text = '1.Черный'; $text = ' 1.Черный'; $text = 'Черный'; $pattern = '/^\s*(?:(\d+)\.)?([^\n]+?)(?:\(([^\)]+)\))?$/'; preg_match($pattern, $text, $out); echo '<pre>'; print_r($out); 
    • Only now I would like to see the number in the array without parentheses without a dot in the array. - KirilLoveVE 7:09 pm
    • @KirilLoveVE corrected the answer - cheops
    • array (0 => '1. Black (black.png)', 1 => '1', 2 => 'Black', 3 => '(black.png)',) And a value is possible (black.png) get without parentheses? - KirilLoveVE
    • @KirilLoveVE corrected the answer :) - cheops