preg_match() cutting line one Black (black.png)



  • Used preg_match() for the selection of that line, which may have several options:

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

    We need to have the meaning of: (1) The figure to the point (if there is a figure with a point) (2) after the point to the brackets (if any) (3) What is in round brackets (if any)

    I've been able to read the options without the meaning of the brackets:

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

    Can you tell me the options or help the council?



  • You can move away from 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);
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2