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['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?:""; }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?:0) . ($max===false?'':',' . ($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.01218.49
8.3.50.0080.01021.46
8.3.40.0090.00619.18
8.3.30.0070.01119.32
8.3.20.0050.00320.34
8.3.10.0040.00421.91
8.3.00.0030.00520.76
8.2.180.0160.00716.63
8.2.170.0110.00422.96
8.2.160.0000.01419.32
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0100.01026.16
8.2.120.0090.00019.48
8.2.110.0000.01022.11
8.2.100.0060.00619.70
8.2.90.0080.00019.47
8.2.80.0040.00418.05
8.2.70.0030.00617.88
8.2.60.0080.00018.05
8.2.50.0050.00318.13
8.2.40.0030.00620.07
8.2.30.0060.00318.23
8.2.20.0040.00417.87
8.2.10.0030.00517.99
8.2.00.0080.00018.01
8.1.280.0120.00325.92
8.1.270.0000.00822.14
8.1.260.0030.00526.35
8.1.250.0050.00328.09
8.1.240.0050.00523.84
8.1.230.0110.00019.04
8.1.220.0030.00617.91
8.1.210.0090.00018.77
8.1.200.0060.00317.60
8.1.190.0060.00317.66
8.1.180.0000.00818.86
8.1.170.0030.00518.84
8.1.160.0040.00422.18
8.1.150.0040.00418.75
8.1.140.0090.00017.74
8.1.130.0040.00417.86
8.1.120.0000.00817.73
8.1.110.0040.00717.70
8.1.100.0030.00517.71
8.1.90.0040.00417.56
8.1.80.0000.00717.71
8.1.70.0070.00017.70
8.1.60.0060.00317.73
8.1.50.0050.00317.74
8.1.40.0080.00017.77
8.1.30.0040.00417.85
8.1.20.0040.00417.83
8.1.10.0040.00417.80
8.1.00.0000.00817.80
8.0.300.0040.00418.77
8.0.290.0060.00317.30
8.0.280.0040.00418.55
8.0.270.0000.00717.32
8.0.260.0030.00317.10
8.0.250.0070.00017.15
8.0.240.0070.00017.20
8.0.230.0050.00317.09
8.0.220.0070.00017.18
8.0.210.0080.00017.16
8.0.200.0040.00417.23
8.0.190.0070.00417.16
8.0.180.0020.00517.19
8.0.170.0040.00417.11
8.0.160.0000.00817.16
8.0.150.0030.00816.99
8.0.140.0020.00516.98
8.0.130.0030.00313.63
8.0.120.0060.00317.11
8.0.110.0000.00717.16
8.0.100.0030.00617.16
8.0.90.0000.00717.14
8.0.80.0030.01317.11
8.0.70.0060.00317.13
8.0.60.0030.00517.17
8.0.50.0000.00716.93
8.0.30.0100.01317.26
8.0.20.0110.00717.49
8.0.10.0030.00517.18
8.0.00.0130.00617.19
7.4.330.0000.00515.18
7.4.320.0000.00616.77
7.4.300.0060.00316.97
7.4.290.0000.00716.78
7.4.280.0030.00316.79
7.4.270.0000.00716.82
7.4.260.0000.00716.88
7.4.250.0030.00516.76
7.4.240.0040.00416.86
7.4.230.0040.00416.91
7.4.220.0060.01216.79
7.4.210.0060.00816.85
7.4.200.0000.00716.71
7.4.190.0040.00416.88
7.4.160.0100.00716.75
7.4.150.0130.00717.40
7.4.140.0040.01417.86
7.4.130.0090.00916.83
7.4.120.0080.01016.85
7.4.110.0070.01316.76
7.4.100.0060.01616.90
7.4.90.0130.00616.92
7.4.80.0040.01419.39
7.4.70.0090.00916.71
7.4.60.0140.00316.85
7.4.50.0040.00416.86
7.4.40.0090.00622.77
7.4.30.0060.01716.88
7.4.00.0070.01015.12
7.3.330.0000.00513.62
7.3.320.0000.00513.61
7.3.310.0050.00216.66
7.3.300.0070.00016.48
7.3.290.0070.01016.62
7.3.280.0090.00916.61
7.3.270.0140.00317.40
7.3.260.0040.02016.70
7.3.250.0090.01016.75
7.3.240.0100.00716.79
7.3.230.0090.00916.66
7.3.210.0090.00916.57
7.3.200.0030.01319.39
7.3.190.0070.01116.87
7.3.180.0060.01016.52
7.3.170.0060.01116.83
7.3.160.0070.01017.02
7.3.120.0040.01415.38
7.2.330.0060.01417.11
7.2.320.0130.00616.96
7.2.310.0160.01216.90
7.2.300.0070.01016.89
7.2.290.0160.00016.93
7.1.70.0000.01017.30
7.1.60.0100.01419.82
7.1.50.0000.01417.16
7.1.00.0100.07022.32
7.0.200.0160.00516.85
7.0.140.0030.07322.10
7.0.100.0130.08020.00
7.0.90.0170.06020.21
7.0.80.0130.08320.00
7.0.70.0200.07319.95
7.0.60.0230.06719.96
7.0.50.0130.05720.42
7.0.40.0130.07320.14
7.0.30.0130.06020.13
7.0.20.0070.08020.13
7.0.10.0100.08320.00
7.0.00.0070.07020.08
5.6.280.0000.07720.95
5.6.250.0000.07720.84
5.6.240.0030.07720.73
5.6.230.0030.08320.65
5.6.220.0030.08320.64
5.6.210.0070.08720.66
5.6.200.0030.08321.17
5.6.190.0130.06321.02
5.6.180.0170.07021.05
5.6.170.0070.08021.05
5.6.160.0100.08021.19
5.6.150.0030.08021.23
5.6.140.0070.07721.06
5.6.130.0170.07021.19
5.6.120.0100.04720.99
5.6.110.0100.06721.13
5.6.100.0030.06021.08
5.6.90.0130.07720.97
5.6.80.0100.08020.48
5.6.70.0130.07320.51
5.6.60.0170.06320.45
5.6.50.0030.06320.61
5.6.40.0070.07720.52
5.6.30.0030.08320.48
5.6.20.0170.05720.45
5.6.10.0070.04320.45
5.6.00.0100.03720.48
5.5.380.0130.07020.44
5.5.370.0000.06320.61
5.5.360.0070.06720.39
5.5.350.0070.08020.52
5.5.340.0070.07320.79
5.5.330.0070.08320.97
5.5.320.0030.08020.97
5.5.310.0030.08020.94
5.5.300.0030.08720.97
5.5.290.0100.07720.69
5.5.280.0100.08320.93
5.5.270.0030.08020.94
5.5.260.0100.07320.95
5.5.250.0070.08720.79
5.5.240.0070.07320.32
5.5.230.0070.08720.30
5.5.220.0100.07020.33
5.5.210.0070.08320.24
5.5.200.0000.08320.29
5.5.190.0070.07020.17
5.5.180.0030.08320.05
5.5.160.0070.07020.24
5.5.150.0070.05720.31
5.5.140.0070.03720.16
5.5.130.0030.04020.05
5.5.120.0030.04020.20
5.5.110.0070.03720.30
5.5.100.0000.04020.08
5.5.90.0030.04020.13
5.5.80.0100.03020.21
5.5.70.0130.04320.08
5.5.60.0070.03720.21
5.5.50.0030.03320.12
5.5.40.0070.06720.14
5.5.30.0030.03720.11
5.5.20.0100.03320.20
5.5.10.0000.05320.18
5.5.00.0030.04020.10
5.4.450.0070.08719.51
5.4.440.0030.07719.46
5.4.430.0000.08319.37
5.4.420.0100.07719.48
5.4.410.0100.08019.33
5.4.400.0070.07718.86
5.4.390.0000.08719.14
5.4.380.0070.07318.86
5.4.370.0100.07719.13
5.4.360.0070.07719.14
5.4.350.0030.06719.05
5.4.340.0070.06019.05
5.4.320.0070.07018.90
5.4.310.0070.04019.21
5.4.300.0000.04718.95
5.4.290.0070.03718.90
5.4.280.0030.04019.05
5.4.270.0030.03718.95
5.4.260.0030.03718.84
5.4.250.0100.03019.13
5.4.240.0030.03718.85
5.4.230.0070.06718.94
5.4.220.0030.08319.16
5.4.210.0030.04719.04
5.4.200.0030.03719.18
5.4.190.0100.06719.14
5.4.180.0100.06719.02
5.4.170.0000.08319.13
5.4.160.0070.06019.19
5.4.150.0030.03319.12
5.4.140.0000.06716.51
5.4.130.0030.03316.46
5.4.120.0000.03716.49
5.4.110.0070.07016.42
5.4.100.0070.04016.42
5.4.90.0070.06716.55
5.4.80.0030.03716.45
5.4.70.0030.06716.40
5.4.60.0000.03316.50
5.4.50.0000.03316.45
5.4.40.0100.03016.30
5.4.30.0030.04716.37
5.4.20.0000.03316.43
5.4.10.0070.03316.41
5.4.00.0070.06015.94
5.3.290.0030.05014.76
5.3.280.0070.03714.65
5.3.270.0030.03714.81
5.3.260.0030.07714.67
5.3.250.0100.07014.79
5.3.240.0030.03714.66
5.3.230.0000.03714.65
5.3.220.0070.07714.67
5.3.210.0030.08014.57
5.3.200.0100.03014.66
5.3.190.0070.03714.65
5.3.180.0070.06714.71
5.3.170.0030.04714.65
5.3.160.0100.04014.78
5.3.150.0000.05714.70
5.3.140.0070.05314.57
5.3.130.0000.03714.58
5.3.120.0030.05014.55
5.3.110.0070.06014.55
5.3.100.0000.04014.04
5.3.90.0030.06014.13
5.3.80.0100.02714.23
5.3.70.0000.05714.04
5.3.60.0000.04314.10
5.3.50.0030.03314.03
5.3.40.0000.05713.95
5.3.30.0030.03313.92
5.3.20.0030.03313.89
5.3.10.0000.03713.80
5.3.00.0100.02313.78

preferences:
40.74 ms | 401 KiB | 5 Q