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' => ''), array('input' => 'a b c d search e f g', 'expected' => ''), array('input' => 'c d search e f g h', 'expected' => ''), array('input' => 'a b c d search e f', 'expected' => ''), array('input' => 'a$@b c d search e f g h', 'expected' => ''), array('input' => 'a b c d search e f g$@h', 'expected' => ''), array('input' => 'a b$@c d search e f g h', 'expected' => ''), array('input' => 'a b c d search e f$@g h', 'expected' => ''), array('input' => 'a b c$@d search e f g h', 'expected' => ''), array('input' => 'a b c d search e$@f g h', 'expected' => ''), array('input' => 'a b c d$@search e f g h', 'expected' => ''), array('input' => 'a b c d search$@e f g h', 'expected' => ''), array('input' => 'a b c d$@search$@e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e f g h', 'expected' => ''), array('input' => 'b c d xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e f g', 'expected' => ''), array('input' => 'c d xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e f', 'expected' => ''), array('input' => 'a$@b c d xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e f g$@h', 'expected' => ''), array('input' => 'a b$@c d xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e f$@g h', 'expected' => ''), array('input' => 'a b c$@d xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx e$@f g h', 'expected' => ''), array('input' => 'a b c d$@xsearchx e f g h', 'expected' => ''), array('input' => 'a b c d xsearchx$@e f g h', 'expected' => ''), array('input' => 'a b c d$@xsearchx$@e f g h', 'expected' => '') ); foreach($tests as $test) { preg_match($reg,$test['input'],$res); assert($res && !empty($res[0]) && $res[0]==$test['expected']); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 40
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 36
Branch analysis from position: 31
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/5VJaR
function name:  (null)
number of ops:  42
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, ->40
         18    > > FE_FETCH_R                                               $11, !3, ->40
   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        ASSERT_CHECK                                             
         26        INIT_FCALL                                               'assert'
         27      > JMPZ_EX                                          ~14     !4, ->31
         28    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~15     !4, 0
         29        BOOL_NOT                                         ~16     ~15
         30        BOOL                                             ~14     ~16
         31    > > JMPZ_EX                                          ~14     ~14, ->36
         32    >   FETCH_DIM_R                                      ~17     !4, 0
         33        FETCH_DIM_R                                      ~18     !3, 'expected'
         34        IS_EQUAL                                         ~19     ~17, ~18
         35        BOOL                                             ~14     ~19
         36    >   SEND_VAL                                                 ~14
         37        SEND_VAL                                                 'assert%28%24res+%26%26+%21empty%28%24res%5B0%5D%29+%26%26+%24res%5B0%5D+%3D%3D+%24test%5B%27expected%27%5D%29'
         38        DO_ICALL                                                 
   37    39      > JMP                                                      ->18
         40    >   FE_FREE                                                  $11
   40    41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.53 ms | 1400 KiB | 21 Q