3v4l.org

run code in 500+ PHP versions simultaneously
<?php $pattern = "/^([A-Z\d]+)\[(?|(\d+)-(\d+)|([A-Z])-([A-Z]))]|([A-Z\d]+)$/"; $strings = [ "SW[1-3]", "LD1[A-D]", "LD1" ]; foreach ($strings as $s) { if (preg_match($pattern, $s, $match)) { if (array_key_exists(4, $match)) { echo $match[4] . PHP_EOL; continue; } foreach (range($match[2], $match[3]) as $m) { echo $match[1] . $m . PHP_EOL; } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 29
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/6sKtS
function name:  (null)
number of ops:  33
compiled vars:  !0 = $pattern, !1 = $strings, !2 = $s, !3 = $match, !4 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%2F%5E%28%5BA-Z%5Cd%5D%2B%29%5C%5B%28%3F%7C%28%5Cd%2B%29-%28%5Cd%2B%29%7C%28%5BA-Z%5D%29-%28%5BA-Z%5D%29%29%5D%7C%28%5BA-Z%5Cd%5D%2B%29%24%2F'
    4     1        ASSIGN                                                       !1, <array>
   10     2      > FE_RESET_R                                           $7      !1, ->31
          3    > > FE_FETCH_R                                                   $7, !2, ->31
   11     4    >   INIT_FCALL                                                   'preg_match'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !2
          7        SEND_REF                                                     !3
          8        DO_ICALL                                             $8      
          9      > JMPZ                                                         $8, ->30
   12    10    >   ARRAY_KEY_EXISTS                                             4, !3
         11      > JMPZ                                                         ~9, ->16
   13    12    >   FETCH_DIM_R                                          ~10     !3, 4
         13        CONCAT                                               ~11     ~10, '%0A'
         14        ECHO                                                         ~11
   14    15      > JMP                                                          ->3
   16    16    >   INIT_FCALL                                                   'range'
         17        FETCH_DIM_R                                          ~12     !3, 2
         18        SEND_VAL                                                     ~12
         19        FETCH_DIM_R                                          ~13     !3, 3
         20        SEND_VAL                                                     ~13
         21        DO_ICALL                                             $14     
         22      > FE_RESET_R                                           $15     $14, ->29
         23    > > FE_FETCH_R                                                   $15, !4, ->29
   17    24    >   FETCH_DIM_R                                          ~16     !3, 1
         25        CONCAT                                               ~17     ~16, !4
         26        CONCAT                                               ~18     ~17, '%0A'
         27        ECHO                                                         ~18
   16    28      > JMP                                                          ->23
         29    >   FE_FREE                                                      $15
   10    30    > > JMP                                                          ->3
         31    >   FE_FREE                                                      $7
   20    32      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.21 ms | 485 KiB | 9 Q