3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ ['word' => 'example', 'mask' => 'lmp'], // true ['word' => 'goodness', 'mask' => 'dns'], // false ['word' => 'slippers', 'mask' => 'eip'], // true ['word' => 'slippers', 'mask' => 'ips'], // false ['word' => 'google', 'mask' => 'go'], // true ['word' => 'food', 'mask' => 'go'], // false ['word' => 'bananas', 'mask' => 'ans'], // true ['word' => 'candle', 'mask' => 'ace'], // false ['word' => 'mississippi', 'mask' => 'i'], // true ['word' => 'executive', 'mask' => 'ecitx'], // false ]; foreach ($tests as ['word' => $word, 'mask' => $mask]) { var_export([ $word, $mask, preg_match_all("/[$mask]+/", $word, $m) && array_filter($m[0], fn($chars) => !ltrim($mask, $chars)), preg_match_all("/[$mask]{" . strlen($mask) . ",}/", $word, $m) && array_filter($m[0], fn($chars) => !ltrim($mask, $chars)), // preg_replace('/[a-z]/', "(?=[$mask]*$0)", $mask), (bool) preg_match('/' . preg_replace('/[a-z]/', "(?=[$mask]*$0)", $mask) . "[$mask]+/", $word) ]); echo "\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 73
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 73
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 49
Branch analysis from position: 28
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
filename:       /in/SRSpN
function name:  (null)
number of ops:  75
compiled vars:  !0 = $tests, !1 = $word, !2 = $mask, !3 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1      > FE_RESET_R                                       $5      !0, ->73
          2    > > FE_FETCH_R                                               $5, $6, ->73
          3    >   FETCH_LIST_R                                     $7      $6, 'word'
          4        ASSIGN                                                   !1, $7
          5        FETCH_LIST_R                                     $9      $6, 'mask'
          6        ASSIGN                                                   !2, $9
          7        FREE                                                     $6
   17     8        INIT_FCALL                                               'var_export'
   18     9        INIT_ARRAY                                       ~11     !1
   19    10        ADD_ARRAY_ELEMENT                                ~11     !2
   20    11        INIT_FCALL                                               'preg_match_all'
         12        ROPE_INIT                                     3  ~13     '%2F%5B'
         13        ROPE_ADD                                      1  ~13     ~13, !2
         14        ROPE_END                                      2  ~12     ~13, '%5D%2B%2F'
         15        SEND_VAL                                                 ~12
         16        SEND_VAR                                                 !1
         17        SEND_REF                                                 !3
         18        DO_ICALL                                         $15     
         19      > JMPZ_EX                                          ~16     $15, ->28
         20    >   INIT_FCALL                                               'array_filter'
         21        FETCH_DIM_R                                      ~17     !3, 0
         22        SEND_VAL                                                 ~17
         23        DECLARE_LAMBDA_FUNCTION                          ~18     [0]
         24        BIND_LEXICAL                                             ~18, !2
         25        SEND_VAL                                                 ~18
         26        DO_ICALL                                         $19     
         27        BOOL                                             ~16     $19
         28    >   ADD_ARRAY_ELEMENT                                ~11     ~16
   21    29        INIT_FCALL                                               'preg_match_all'
         30        ROPE_INIT                                     3  ~21     '%2F%5B'
         31        ROPE_ADD                                      1  ~21     ~21, !2
         32        ROPE_END                                      2  ~20     ~21, '%5D%7B'
         33        STRLEN                                           ~23     !2
         34        CONCAT                                           ~24     ~20, ~23
         35        CONCAT                                           ~25     ~24, '%2C%7D%2F'
         36        SEND_VAL                                                 ~25
         37        SEND_VAR                                                 !1
         38        SEND_REF                                                 !3
         39        DO_ICALL                                         $26     
         40      > JMPZ_EX                                          ~27     $26, ->49
         41    >   INIT_FCALL                                               'array_filter'
         42        FETCH_DIM_R                                      ~28     !3, 0
         43        SEND_VAL                                                 ~28
         44        DECLARE_LAMBDA_FUNCTION                          ~29     [1]
         45        BIND_LEXICAL                                             ~29, !2
         46        SEND_VAL                                                 ~29
         47        DO_ICALL                                         $30     
         48        BOOL                                             ~27     $30
         49    >   ADD_ARRAY_ELEMENT                                ~11     ~27
   23    50        INIT_FCALL                                               'preg_match'
         51        INIT_FCALL                                               'preg_replace'
         52        SEND_VAL                                                 '%2F%5Ba-z%5D%2F'
         53        ROPE_INIT                                     3  ~32     '%28%3F%3D%5B'
         54        ROPE_ADD                                      1  ~32     ~32, !2
         55        ROPE_END                                      2  ~31     ~32, '%5D%2A%240%29'
         56        SEND_VAL                                                 ~31
         57        SEND_VAR                                                 !2
         58        DO_ICALL                                         $34     
         59        CONCAT                                           ~35     '%2F', $34
         60        ROPE_INIT                                     3  ~37     '%5B'
         61        ROPE_ADD                                      1  ~37     ~37, !2
         62        ROPE_END                                      2  ~36     ~37, '%5D%2B%2F'
         63        CONCAT                                           ~39     ~35, ~36
         64        SEND_VAL                                                 ~39
         65        SEND_VAR                                                 !1
         66        DO_ICALL                                         $40     
         67        BOOL                                             ~41     $40
         68        ADD_ARRAY_ELEMENT                                ~11     ~41
         69        SEND_VAL                                                 ~11
   17    70        DO_ICALL                                                 
   25    71        ECHO                                                     '%0A---%0A'
   16    72      > JMP                                                      ->2
         73    >   FE_FREE                                                  $5
   26    74      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SRSpN
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $chars, !1 = $mask
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'ltrim'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > RETURN                                                   ~3
          8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SRSpN
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $chars, !1 = $mask
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'ltrim'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > RETURN                                                   ~3
          8*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.92 ms | 1025 KiB | 19 Q