fork download
  1. <?php
  2. $input = '[Lorem ipsum]
  3. Dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
  4.  
  5. [Ut wisi]
  6. [Enim ad minim veniam](a), quis nostrud exerci tation ullamcorper.
  7. suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat.
  8. Vel illum dolore eu feugiat nulla facilisis at vero.
  9. [Ros et accumsan et iusto odio dignissim](b) qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
  10.  
  11. [[Nam liber]](c)
  12. Tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.';
  13.  
  14. \[( # open outer square brackets and capturing group
  15. (?: # open subpattern for optional inner square brackets
  16. [^[\]]* # non-square-bracket characters
  17. \[ # open inner square bracket
  18. [^[\]]* # non-square-bracket characters
  19. ] # close inner square bracket
  20. )* # end subpattern and repeat it 0 or more times
  21. [^[\]]* # non-square-bracket characters
  22. )] # end capturing group and outer square brackets
  23. (?: # open subpattern for optional parentheses
  24. \(( # open parentheses and capturing group
  25. [a-z]+ # letters
  26. )\) # close capturing group and parentheses
  27. )? # end subpattern and make it optional
  28. ~isx",
  29. $input,
  30. $matches);
  31.  
  32. print_r($matches);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => [Lorem ipsum]
            [1] => [Ut wisi]
            [2] => [Enim ad minim veniam](a)
            [3] => [Ros et accumsan et iusto odio dignissim](b)
            [4] => [[Nam liber]](c)
        )

    [1] => Array
        (
            [0] => Lorem ipsum
            [1] => Ut wisi
            [2] => Enim ad minim veniam
            [3] => Ros et accumsan et iusto odio dignissim
            [4] => [Nam liber]
        )

    [2] => Array
        (
            [0] => 
            [1] => 
            [2] => a
            [3] => b
            [4] => c
        )

)