3v4l.org

run code in 300+ PHP versions simultaneously
<?php function RC($flags = ""){ return new RegCode($flags); } class RegCodeFn { public static function escape($s){ return preg_replace("/[\\/\\\\\\^\\[\\]\\.\\$\\{\\}\\*\\+\\(\\)\\|\\?\\<\\>]/", "\\\\$0", $s); } public static function compileArr($chain){ $l = count($chain); $code = ""; for ($i=0; $i < $l; $i++) { $code .= RegCodeFn::compile($chain[$i],($i + 1) < $l ? $chain[$i+1]['type'] == 'repeat' : false); } return $code; } public static function compile($item, $repeatNext){ switch ($item['type']) { case 'range': return '[' . ($item['not']?'^':'') . $item['allowed'] . ']'; break; case 'group': $res = RegCodeFn::compileArr($item['chain']); return '(' . ($item['assertion']?$item['assertion']:'') . ($item['name']?(($item['assertion']?'':'?') . 'P<' . $item['name'] . '>' ):'') . $res['code'] . ')'; break; case 'raw': case 'text': if($repeatNext && strlen($item['code']) > 1 && !(strlen($item['code']) == 2 && $item['code'][1] == '\\')){ return '(?:' . $item['code'] . ')'; }else{ return $item['code']; } break; case 'any': return "."; break; case 'end': return '$'; break; case 'start': return '^'; break; case 'repeat': return $item['code']; break; } } } class RegCode { public $flags; public $chain; public function __construct($flags = ""){ if(is_string($flags)){ $this->flags = $flags?$flags:""; }else{ $this->flags = $flags->flags; $this->chain = clone $flags->chain; } } public function start(){ $this->chain[] = array('type'=>"start"); return $this; } public function end(){ $this->chain[] = array('type'=>"end"); return $this; } public function range($allowed, $escape = true){ if($escape) $allowed = RegCodeFn::escape($allowed); $this->chain[] = array( 'type'=>'range', 'not'=>false, "allowed"=>$allowed ); return $this; } public function notRange($allowed, $escape = true){ if($escape == null) $escape = true; if($escape) $allowed = RegCodeFn::escape($allowed); $this->chain[] = array( 'type'=>'range', 'not'=>true, "allowed"=>$allowed ); return $this; } public function group($name, $assertion = null, $chain = null){ $chain = $chain == null?($assertion == null ? $name : $assertion):$chain; $assertion = is_string($assertion) ? $assertion : false; $name = is_string($name) ? $name : false; $this->chain[] = array( 'type'=>'group', 'assertion'=>$assertion, 'name'=>$name, 'chain'=>$chain->chain ); return $this; } public function any(){ $this->chain[] = array("type"=>'any'); return $this; } public function repeat($min, $max = false){ $code = ($min == '?' && $min == '*' && $min == '+')?$min:'{'.($min?$min:0) . ($max===false?'':',' . ($max?$max:'')) . '}'; $this->chain[] = array( "type"=>"repeat", "code"=>$code ); return $this; } public function raw($code){ $this->chain[] = array( "type"=>'raw', "code"=>$code ); return $this; } public function text($text,$escape){ if($escape == null) $escape = true; $this->chain[] = array( 'type'=>'text', "code"=>$escape?RegCodeFn::escape($text):$text ); return $this; } public function __toString(){ return "/" . RegCodeFn::compileArr($this->chain) . "/" . $this->flags; } public function compile($force){ return new RegCodeCompiled(RegCodeFn::compileArr($this->chain), $this->flags); } } class RegCodeCompiled { public $code; public $flags; public function __construct($code, $flags){ $this->code = $code; $this->flags = $flags; } public function match($subject, &$matches = null, $flags = 0, $offset = 0){ return preg_match("/" . $this->code . "/" . $this->flags, $subject, $matches, $flags, $offset); } public function match_all(){ } public function replace($replacement, $subject, $limit = -1, &$count = null){ return preg_replace("/" . $this->code . "/" . $this->flags, $replacement, $subject, $limit, $count); } public function replace_callback($callback, $subject, $limit = -1, &$count = null){ return preg_replace_callback("/" . $this->code . "/" . $this->flags, $callback, $subject, $limit, $count); } } echo RC() ->start() ->range('a-z') ->range('a-z0-9')->repeat(3,null) ->end();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0120.00918.55
8.3.50.0050.01421.33
8.3.40.0090.00618.92
8.3.30.0090.01218.96
8.3.20.0040.00420.29
8.3.10.0050.00322.04
8.3.00.0000.00820.80
8.2.180.0150.00716.63
8.2.170.0120.00322.96
8.2.160.0140.00719.46
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0070.01326.16
8.2.120.0050.00319.48
8.2.110.0030.00622.08
8.2.100.0060.00619.57
8.2.90.0040.00419.48
8.2.80.0030.00618.05
8.2.70.0000.00818.00
8.2.60.0040.00418.05
8.2.50.0030.00518.07
8.2.40.0080.00020.01
8.2.30.0050.00318.25
8.2.20.0080.00017.92
8.2.10.0000.00817.99
8.2.00.0060.00317.97
8.1.280.0110.00325.92
8.1.270.0050.00322.13
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0040.00723.77
8.1.230.0040.00819.36
8.1.220.0030.00517.80
8.1.210.0030.00618.77
8.1.200.0030.00717.60
8.1.190.0000.00817.65
8.1.180.0050.00318.95
8.1.170.0000.00818.82
8.1.160.0040.00422.21
8.1.150.0030.00518.84
8.1.140.0110.00017.63
8.1.130.0040.00417.82
8.1.120.0040.00317.64
8.1.110.0030.00917.74
8.1.100.0040.00417.57
8.1.90.0000.00717.68
8.1.80.0040.00417.73
8.1.70.0020.00517.67
8.1.60.0000.00817.87
8.1.50.0030.00617.78
8.1.40.0000.00817.79
8.1.30.0100.00017.77
8.1.20.0040.00417.76
8.1.10.0040.00417.65
8.1.00.0000.00817.70
8.0.300.0000.00718.77
8.0.290.0000.00817.30
8.0.280.0040.00418.56
8.0.270.0050.00317.38
8.0.260.0000.00717.06
8.0.250.0070.00017.07
8.0.240.0040.00417.11
8.0.230.0060.00317.06
8.0.220.0000.00817.12
8.0.210.0080.00017.10
8.0.200.0040.00417.23
8.0.190.0000.00917.08
8.0.180.0000.00817.09
8.0.170.0030.00517.13
8.0.160.0000.00717.15
8.0.150.0040.00417.10
8.0.140.0060.00316.96
8.0.130.0000.00613.58
8.0.120.0030.00617.07
8.0.110.0030.00617.14
8.0.100.0070.00017.18
8.0.90.0000.00816.93
8.0.80.0110.01117.09
8.0.70.0000.00817.09
8.0.60.0030.00517.02
8.0.50.0080.00016.91
8.0.30.0120.01117.40
8.0.20.0120.00617.43
8.0.10.0040.00417.14
8.0.00.0130.00717.15
7.4.330.0000.00615.11
7.4.320.0000.00616.82
7.4.300.0030.00616.76
7.4.290.0000.00716.73
7.4.280.0000.00716.89
7.4.270.0040.00416.80
7.4.260.0070.00316.81
7.4.250.0040.00416.78
7.4.240.0040.00416.85
7.4.230.0080.00016.64
7.4.220.0090.00916.85
7.4.210.0060.00816.88
7.4.200.0020.00516.89
7.4.190.0030.00316.71
7.4.160.0110.00616.79
7.4.150.0090.00917.40
7.4.140.0130.00917.86
7.4.130.0110.00616.89
7.4.120.0130.00516.90
7.4.110.0150.00416.82
7.4.100.0030.01716.74
7.4.90.0030.01516.75
7.4.80.0120.00919.39
7.4.70.0100.00716.71
7.4.60.0080.00816.71
7.4.50.0050.00016.86
7.4.40.0100.00722.77
7.4.30.0060.01616.80
7.4.00.0080.00815.30
7.3.330.0000.00513.61
7.3.320.0000.00613.45
7.3.310.0070.00016.62
7.3.300.0030.00316.47
7.3.290.0100.01316.71
7.3.280.0070.01016.67
7.3.270.0070.01017.40
7.3.260.0060.01516.58
7.3.250.0120.01016.83
7.3.240.0110.00816.63
7.3.230.0090.00916.65
7.3.210.0080.01116.61
7.3.200.0060.01619.39
7.3.190.0060.01216.84
7.3.180.0030.01316.54
7.3.170.0100.00616.88
7.3.160.0030.01316.58
7.3.120.0070.00915.22
7.3.110.0050.01114.96
7.3.100.0030.01115.11
7.3.90.0060.00815.09
7.3.80.0080.00815.12
7.3.70.0050.00915.01
7.3.60.0030.01015.05
7.3.50.0070.00914.96
7.3.40.0070.00615.19
7.3.30.0070.00915.21
7.3.20.0050.01017.00
7.3.10.0060.00716.67
7.3.00.0060.01016.93
7.2.330.0100.01016.95
7.2.320.0080.00817.05
7.2.310.0060.01016.83
7.2.300.0130.00316.95
7.2.290.0000.01716.86
7.2.250.0120.00815.47
7.2.240.0080.01015.27
7.2.230.0100.00515.22
7.2.220.0070.00915.18
7.2.210.0050.01015.30
7.2.200.0050.01115.54
7.2.190.0060.00815.38
7.2.180.0030.01315.22
7.2.170.0050.01115.31
7.2.160.0050.00915.33
7.2.150.0030.01017.25
7.2.140.0030.01317.23
7.2.130.0060.01017.13
7.2.120.0060.01316.89
7.2.110.0030.01117.33
7.2.100.0030.01117.05
7.2.90.0030.01217.20
7.2.80.0090.00917.22
7.2.70.0030.01017.22
7.2.60.0060.00617.05
7.2.50.0070.01017.23
7.2.40.0090.00617.37
7.2.30.0040.01117.16
7.2.20.0030.00716.90
7.2.10.0070.01117.23
7.2.00.0040.01218.40
7.1.330.0060.01116.01
7.1.320.0000.01216.22
7.1.310.0030.01116.02
7.1.300.0050.00915.80
7.1.290.0030.00616.05
7.1.280.0050.00815.85
7.1.270.0070.00516.10
7.1.260.0030.01015.97
7.1.250.0120.00615.79
7.1.240.0030.01415.85
7.1.230.0070.01015.73
7.1.220.0000.01116.05
7.1.210.0100.00315.95
7.1.200.0070.00915.71
7.1.190.0070.00415.80
7.1.180.0000.01216.02
7.1.170.0000.01416.09
7.1.160.0030.00615.89
7.1.150.0070.00715.77
7.1.140.0000.01015.79
7.1.130.0000.01016.16
7.1.120.0030.01215.92
7.1.110.0100.00315.86
7.1.100.0040.00717.30
7.1.90.0030.00615.99
7.1.80.0000.01416.16
7.1.70.0070.00316.66
7.1.60.0030.01417.89
7.1.50.0090.00516.66
7.1.40.0030.00815.81
7.1.30.0070.01016.12
7.1.20.0110.00415.68
7.1.10.0030.01016.07
7.1.00.0070.04019.20
7.0.330.0040.00815.63
7.0.320.0000.01515.75
7.0.310.0030.00915.79
7.0.300.0120.00315.79
7.0.290.0030.00915.24
7.0.280.0110.00415.63
7.0.270.0040.00815.75
7.0.260.0090.00615.45
7.0.250.0090.00915.60
7.0.240.0140.00015.49
7.0.230.0060.00915.62
7.0.220.0040.01215.70
7.0.210.0080.01215.57
7.0.200.0150.00316.18
7.0.190.0000.01215.75
7.0.180.0050.00815.31
7.0.170.0040.01115.59
7.0.160.0070.01015.31
7.0.150.0050.00515.39
7.0.140.0030.04118.73
7.0.130.0030.00915.74
7.0.120.0000.01415.73
7.0.110.0090.00315.76
7.0.100.0050.03017.82
7.0.90.0030.04717.71
7.0.80.0080.03917.86
7.0.70.0070.04117.77
7.0.60.0070.04217.87
7.0.50.0300.03217.99
7.0.40.0060.03516.74
7.0.30.0050.04616.82
7.0.20.0130.04216.75
7.0.10.0050.04516.69
7.0.00.0120.04216.75
5.6.400.0000.01214.30
5.6.390.0070.01014.80
5.6.380.0060.00914.64
5.6.370.0000.01514.63
5.6.360.0000.01314.78
5.6.350.0030.01214.57
5.6.340.0000.00914.92
5.6.330.0000.01214.33
5.6.320.0000.01214.76
5.6.310.0040.01414.52
5.6.300.0000.01014.84
5.6.290.0040.01114.46
5.6.280.0050.04118.07
5.6.270.0060.00614.59
5.6.260.0030.01014.55
5.6.250.0030.05317.64
5.6.240.0060.04117.66
5.6.230.0030.05017.78
5.6.220.0030.04317.54
5.6.210.0020.04417.68
5.6.200.0060.04617.79
5.6.190.0080.04517.73
5.6.180.0050.03118.01
5.6.170.0050.04417.78
5.6.160.0050.04917.77
5.6.150.0020.04917.79
5.6.140.0070.04317.72
5.6.130.0120.03817.85
5.6.120.0110.04617.91
5.6.110.0090.04217.84
5.6.100.0050.04317.83
5.6.90.0030.03917.79
5.6.80.0060.03817.46
5.6.70.0050.04517.34
5.6.60.0080.02117.59
5.6.50.0050.04017.57
5.6.40.0080.04017.52
5.6.30.0120.03817.46
5.6.20.0050.04417.39
5.6.10.0100.04017.38
5.6.00.0050.04917.55
5.5.380.0120.04217.48
5.5.370.0110.03617.60
5.5.360.0070.04217.58
5.5.350.0080.04317.31
5.5.340.0110.04117.72
5.5.330.0100.04017.70
5.5.320.0100.04017.70
5.5.310.0100.04517.92
5.5.300.0080.04317.59
5.5.290.0090.04317.79
5.5.280.0070.04517.71
5.5.270.0030.04817.69
5.5.260.0050.04317.69
5.5.250.0080.04417.68
5.5.240.0050.04417.44
5.5.230.0070.04717.42
5.5.220.0070.04017.44
5.5.210.0050.04317.38
5.5.200.0130.04017.32
5.5.190.0150.03217.41
5.5.180.0140.03217.29
5.5.170.0030.01014.67
5.5.160.0070.03817.45
5.5.150.0020.02717.31
5.5.140.0030.02817.28
5.5.130.0080.04317.45
5.5.120.0020.02417.53
5.5.110.0120.03317.41
5.5.100.0080.02317.37
5.5.90.0070.02617.23
5.5.80.0060.02217.18
5.5.70.0020.02417.27
5.5.60.0040.02117.42
5.5.50.0100.01917.34
5.5.40.0080.02017.42
5.5.30.0030.02717.46
5.5.20.0040.02317.48
5.5.10.0050.02517.24
5.5.00.0110.02817.34
5.4.450.0050.04415.48
5.4.440.0050.03215.36
5.4.430.0110.03315.23
5.4.420.0050.04515.53
5.4.410.0080.04015.29
5.4.400.0050.04415.21
5.4.390.0030.02915.15
5.4.380.0060.04115.26
5.4.370.0080.01715.31
5.4.360.0070.04215.19
5.4.350.0050.04115.31
5.4.340.0080.04115.15
5.4.330.0060.00611.36
5.4.320.0080.04215.08
5.4.310.0020.03115.17
5.4.300.0020.04415.36
5.4.290.0030.04515.24
5.4.280.0020.02615.21
5.4.270.0060.02015.27
5.4.260.0020.02415.12
5.4.250.0080.04115.31
5.4.240.0070.02215.24
5.4.230.0030.02315.06
5.4.220.0000.03415.25
5.4.210.0050.03415.26
5.4.200.0070.02715.12
5.4.190.0020.02215.29
5.4.180.0040.02215.17
5.4.170.0030.02115.15
5.4.160.0070.03515.06
5.4.150.0050.04115.16
5.4.140.0020.02313.94
5.4.130.0030.03813.94
5.4.120.0030.02113.88
5.4.110.0060.02113.98
5.4.100.0000.04413.78
5.4.90.0080.01713.85
5.4.80.0020.02013.79
5.4.70.0070.01713.94
5.4.60.0050.02513.88
5.4.50.0030.02013.79
5.4.40.0050.02213.88
5.4.30.0030.03413.94
5.4.20.0030.03213.83
5.4.10.0030.02313.87
5.4.00.0060.01613.58
5.3.290.0050.02413.00
5.3.280.0020.02312.97
5.3.270.0050.02012.99
5.3.260.0030.02212.92
5.3.250.0050.01713.03
5.3.240.0020.02913.00
5.3.230.0080.04112.96
5.3.220.0030.02612.93
5.3.210.0050.01812.96
5.3.200.0030.02212.90
5.3.190.0030.02012.95
5.3.180.0020.02412.93
5.3.170.0020.03412.96
5.3.160.0000.02712.99
5.3.150.0020.02512.98
5.3.140.0020.02512.92
5.3.130.0080.03612.98
5.3.120.0040.02312.90
5.3.110.0020.02413.00
5.3.100.0030.02312.73
5.3.90.0030.02312.62
5.3.80.0050.02012.67
5.3.70.0050.02312.63
5.3.60.0030.02512.71
5.3.50.0040.01912.63
5.3.40.0050.02012.64
5.3.30.0050.01812.57
5.3.20.0020.02812.53
5.3.10.0070.01712.55
5.3.00.0050.01912.50

preferences:
37.1 ms | 401 KiB | 5 Q