3v4l.org

run code in 300+ PHP versions simultaneously
<?php $meta_pattern = '/(?<=^|%3$s|\s)(?:(?!\S*%3$s\S*)\S+\s+){0,%2$d}(?:(?!\S*%3$s\S*%1$s)\S*)?%1$s\S*?(?:\s+\S+?){0,%2$d}(?=$|%3$s|\s)/'; $reg = sprintf($meta_pattern, preg_quote('search','/'), 3, preg_quote('$@','/')); $tests = array( array('input' => 'a b c d search e f g h', 'expected' => 'b c d search e f g'), array('input' => 'b c d search e f g h', 'expected' => 'b c d search e f g'), array('input' => 'a b c d search e f g', 'expected' => 'b c d search e f g'), array('input' => 'c d search e f g h', 'expected' => 'c d search e f g'), array('input' => 'a b c d search e f', 'expected' => 'b c d search e f'), array('input' => 'a$@b c d search e f g h', 'expected' => 'b c d search e f g'), array('input' => 'a b c d search e f g$@h', 'expected' => 'b c d search e f g'), array('input' => 'a b$@c d search e f g h', 'expected' => 'c d search e f g'), array('input' => 'a b c d search e f$@g h', 'expected' => 'b c d search e f'), array('input' => 'a b c$@d search e f g h', 'expected' => 'd search e f g'), array('input' => 'a b c d search e$@f g h', 'expected' => 'b c d search e'), array('input' => 'a b c d$@search e f g h', 'expected' => 'search e f g'), array('input' => 'a b c d search$@e f g h', 'expected' => 'b c d search'), array('input' => 'a b c d$@search$@e f g h', 'expected' => 'search'), array('input' => 'a b c d xsearchx e f g h', 'expected' => 'b c d xsearchx e f g'), array('input' => 'b c d xsearchx e f g h', 'expected' => 'b c d xsearchx e f g'), array('input' => 'a b c d xsearchx e f g', 'expected' => 'b c d xsearchx e f g'), array('input' => 'c d xsearchx e f g h', 'expected' => 'c d xsearchx e f g'), array('input' => 'a b c d xsearchx e f', 'expected' => 'b c d xsearchx e f'), array('input' => 'a$@b c d xsearchx e f g h', 'expected' => 'b c d xsearchx e f g'), array('input' => 'a b c d xsearchx e f g$@h', 'expected' => 'b c d xsearchx e f g'), array('input' => 'a b$@c d xsearchx e f g h', 'expected' => 'c d xsearchx e f g'), array('input' => 'a b c d xsearchx e f$@g h', 'expected' => 'b c d xsearchx e f'), array('input' => 'a b c$@d xsearchx e f g h', 'expected' => 'd xsearchx e f g'), array('input' => 'a b c d xsearchx e$@f g h', 'expected' => 'b c d xsearchx e'), array('input' => 'a b c d$@xsearchx e f g h', 'expected' => 'xsearchx e f g'), array('input' => 'a b c d xsearchx$@e f g h', 'expected' => 'b c d xsearchx'), array('input' => 'a b c d$@xsearchx$@e f g h', 'expected' => 'xsearchx') ); foreach($tests as $test) { preg_match($reg,$test['input'],$res); if(!($res && !empty($res[0]) && $res[0]==$test['expected'])) { var_dump('Test '.$test['input'].' failed.'); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 43
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 43
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 42
Branch analysis from position: 34
Branch analysis from position: 29
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/7Yhft
function name:  (null)
number of ops:  45
compiled vars:  !0 = $meta_pattern, !1 = $reg, !2 = $tests, !3 = $test, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%2F%28%3F%3C%3D%5E%7C%253%24s%7C%5Cs%29%28%3F%3A%28%3F%21%5CS%2A%253%24s%5CS%2A%29%5CS%2B%5Cs%2B%29%7B0%2C%252%24d%7D%28%3F%3A%28%3F%21%5CS%2A%253%24s%5CS%2A%251%24s%29%5CS%2A%29%3F%251%24s%5CS%2A%3F%28%3F%3A%5Cs%2B%5CS%2B%3F%29%7B0%2C%252%24d%7D%28%3F%3D%24%7C%253%24s%7C%5Cs%29%2F'
    4     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAR                                                 !0
          3        INIT_FCALL                                               'preg_quote'
          4        SEND_VAL                                                 'search'
          5        SEND_VAL                                                 '%2F'
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        SEND_VAL                                                 3
          9        INIT_FCALL                                               'preg_quote'
         10        SEND_VAL                                                 '%24%40'
         11        SEND_VAL                                                 '%2F'
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !1, $8
    6    16        ASSIGN                                                   !2, <array>
   37    17      > FE_RESET_R                                       $11     !2, ->43
         18    > > FE_FETCH_R                                               $11, !3, ->43
   38    19    >   INIT_FCALL                                               'preg_match'
         20        SEND_VAR                                                 !1
         21        FETCH_DIM_R                                      ~12     !3, 'input'
         22        SEND_VAL                                                 ~12
         23        SEND_REF                                                 !4
         24        DO_ICALL                                                 
   39    25      > JMPZ_EX                                          ~14     !4, ->29
         26    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~15     !4, 0
         27        BOOL_NOT                                         ~16     ~15
         28        BOOL                                             ~14     ~16
         29    > > JMPZ_EX                                          ~14     ~14, ->34
         30    >   FETCH_DIM_R                                      ~17     !4, 0
         31        FETCH_DIM_R                                      ~18     !3, 'expected'
         32        IS_EQUAL                                         ~19     ~17, ~18
         33        BOOL                                             ~14     ~19
         34    >   BOOL_NOT                                         ~20     ~14
         35      > JMPZ                                                     ~20, ->42
   40    36    >   INIT_FCALL                                               'var_dump'
         37        FETCH_DIM_R                                      ~21     !3, 'input'
         38        CONCAT                                           ~22     'Test+', ~21
         39        CONCAT                                           ~23     ~22, '+failed.'
         40        SEND_VAL                                                 ~23
         41        DO_ICALL                                                 
   37    42    > > JMP                                                      ->18
         43    >   FE_FREE                                                  $11
   42    44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.98 ms | 1400 KiB | 21 Q