3v4l.org

run code in 500+ 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 = 67
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 67
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: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
filename:       /in/SRSpN
function name:  (null)
number of ops:  69
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, ->67
          2    > > FE_FETCH_R                                                   $5, $6, ->67
          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        ROPE_INIT                                         3  ~32     '%28%3F%3D%5B'
         51        ROPE_ADD                                          1  ~32     ~32, !2
         52        ROPE_END                                          2  ~31     ~32, '%5D%2A%240%29'
         53        FRAMELESS_ICALL_3                preg_replace        ~34     '%2F%5Ba-z%5D%2F', ~31
         54        OP_DATA                                                      !2
         55        CONCAT                                               ~35     '%2F', ~34
         56        ROPE_INIT                                         3  ~37     '%5B'
         57        ROPE_ADD                                          1  ~37     ~37, !2
         58        ROPE_END                                          2  ~36     ~37, '%5D%2B%2F'
         59        CONCAT                                               ~39     ~35, ~36
         60        FRAMELESS_ICALL_2                preg_match          ~40     ~39, !1
         61        BOOL                                                 ~41     ~40
         62        ADD_ARRAY_ELEMENT                                    ~11     ~41
         63        SEND_VAL                                                     ~11
   17    64        DO_ICALL                                                     
   25    65        ECHO                                                         '%0A---%0A'
   16    66      > JMP                                                          ->2
         67    >   FE_FREE                                                      $5
   26    68      > 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:/in/SRSpN:20}
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:/in/SRSpN:21}
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.5.0


preferences:
204.02 ms | 2043 KiB | 17 Q