fork download
  1. <?php
  2. $text = "a b c d [a b c Str1 d e f Str2 g h i Str3 ] e f g Str4 [Str5 a b c Str6 d] h i";
  3. $re1 = "/\\[[^\\]]*\\]/s";
  4. $re2 = "/\\bStr\\d+\\b/";
  5. preg_match_all( $re1, $text, $arr1 );
  6. foreach ( $arr1[0] as $k=>$v ) {
  7. preg_match_all( $re2, $v, $arr2 );
  8. // обработка результата, например так:
  9. var_dump( $arr2[0] );
  10. };
  11.  
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(4) "Str1"
  [1]=>
  string(4) "Str2"
  [2]=>
  string(4) "Str3"
}
array(2) {
  [0]=>
  string(4) "Str5"
  [1]=>
  string(4) "Str6"
}