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.0040.01218.68
8.3.50.0120.01022.17
8.3.40.0120.00319.04
8.3.30.0150.00019.11
8.3.20.0030.00518.98
8.3.10.0000.00820.73
8.3.00.0000.00919.63
8.2.180.0150.00616.75
8.2.170.0140.00422.96
8.2.160.0070.01022.23
8.2.150.0050.00324.18
8.2.140.0030.00624.66
8.2.130.0060.00326.16
8.2.120.0050.00319.77
8.2.110.0060.00322.20
8.2.100.0060.00618.16
8.2.90.0050.00319.38
8.2.80.0000.00818.04
8.2.70.0030.00617.74
8.2.60.0060.00318.05
8.2.50.0040.00418.07
8.2.40.0000.00818.25
8.2.30.0030.00519.79
8.2.20.0000.00817.90
8.2.10.0030.00618.01
8.2.00.0040.00417.84
8.1.280.0070.01025.92
8.1.270.0040.00423.99
8.1.260.0000.00726.35
8.1.250.0050.00328.09
8.1.240.0000.00922.60
8.1.230.0110.00021.08
8.1.220.0030.00718.77
8.1.210.0060.00319.02
8.1.200.0030.00917.38
8.1.190.0000.00817.75
8.1.180.0000.00818.10
8.1.170.0040.00418.81
8.1.160.0000.00719.07
8.1.150.0040.00418.93
8.1.140.0040.00417.61
8.1.130.0030.00317.94
8.1.120.0050.00317.60
8.1.110.0040.00417.64
8.1.100.0070.00017.59
8.1.90.0000.00817.60
8.1.80.0040.00417.75
8.1.70.0070.00017.69
8.1.60.0030.00517.84
8.1.50.0080.00017.69
8.1.40.0000.01017.79
8.1.30.0000.00817.93
8.1.20.0000.00817.81
8.1.10.0000.00917.69
8.1.00.0050.00317.62
8.0.300.0030.00620.14
8.0.290.0000.00816.75
8.0.280.0000.00718.55
8.0.270.0000.00717.26
8.0.260.0000.00717.00
8.0.250.0030.00517.17
8.0.240.0000.00817.10
8.0.230.0050.00317.17
8.0.220.0000.01017.09
8.0.210.0030.00317.05
8.0.200.0090.00017.07
8.0.190.0000.00717.07
8.0.180.0000.00917.19
8.0.170.0000.01017.17
8.0.160.0070.00016.97
8.0.150.0050.00516.98
8.0.140.0000.00917.09
8.0.130.0000.00713.60
8.0.120.0040.00417.00
8.0.110.0030.00617.08
8.0.100.0080.00017.22
8.0.90.0000.00817.18
8.0.80.0030.01417.12
8.0.70.0000.00717.00
8.0.60.0000.00817.11
8.0.50.0040.00417.19
8.0.30.0140.00517.12
8.0.20.0060.01217.49
8.0.10.0050.00317.17
8.0.00.0100.01117.11
7.4.330.0050.00013.43
7.4.320.0040.00416.86
7.4.300.0000.00616.91
7.4.290.0030.00316.93
7.4.280.0050.00316.82
7.4.270.0030.00316.80
7.4.260.0030.00313.51
7.4.250.0090.00016.86
7.4.240.0000.00716.80
7.4.230.0040.00416.94
7.4.220.0210.00616.86
7.4.210.0090.00616.91
7.4.200.0000.00716.83
7.4.190.0050.00216.80
7.4.160.0170.00016.85
7.4.150.0160.01417.40
7.4.140.0090.01017.39
7.4.130.0140.00616.84
7.4.120.0110.00816.88
7.4.110.0190.00316.50
7.4.100.0120.00916.70
7.4.90.0070.01516.88
7.4.80.0100.00719.03
7.4.70.0060.01216.74
7.4.60.0120.00416.75
7.4.50.0040.00416.76
7.4.40.0060.00922.27
7.4.30.0090.00616.43
7.4.10.0070.01115.39
7.4.00.0030.01115.27
7.3.330.0030.00313.61
7.3.320.0000.00613.58
7.3.310.0030.00416.63
7.3.300.0030.00516.48
7.3.290.0070.00716.57
7.3.280.0090.01016.63
7.3.270.0090.00817.40
7.3.260.0080.01318.24
7.3.250.0170.00316.73
7.3.240.0090.00916.77
7.3.230.0060.01216.80
7.3.210.0130.01016.85
7.3.200.0030.01519.39
7.3.190.0110.00716.81
7.3.180.0120.00616.66
7.3.170.0070.01416.85
7.3.160.0050.01116.66
7.3.130.0030.01315.16
7.3.120.0030.01315.00
7.3.110.0100.01014.96
7.3.100.0080.00314.89
7.3.90.0030.00614.95
7.3.80.0000.01415.02
7.3.70.0060.00515.07
7.3.60.0050.01015.08
7.3.50.0100.00315.24
7.3.40.0070.00715.18
7.3.30.0110.00415.13
7.3.20.0110.00716.61
7.3.10.0050.01416.64
7.3.00.0060.01316.76
7.2.330.0060.01316.99
7.2.320.0070.01016.77
7.2.310.0090.00917.10
7.2.300.0070.01016.73
7.2.290.0090.00916.97
7.2.260.0160.00315.24
7.2.250.0090.00915.12
7.2.240.0150.00315.38
7.2.230.0030.00915.09
7.2.220.0000.00915.30
7.2.210.0000.00915.44
7.2.200.0130.00315.15
7.2.190.0070.01115.34
7.2.180.0070.00715.08
7.2.170.0030.00815.02
7.2.160.0100.00715.46
7.2.150.0080.00816.89
7.2.140.0040.01917.16
7.2.130.0060.01417.02
7.2.120.0060.00617.02
7.2.110.0070.01017.21
7.2.100.0030.01017.14
7.2.90.0000.01216.98
7.2.80.0070.00317.11
7.2.70.0060.00617.18
7.2.60.0040.01417.29
7.2.50.0100.00316.98
7.2.40.0120.00017.00
7.2.30.0130.00017.09
7.2.20.0070.00717.17
7.2.10.0060.00917.04
7.2.00.0080.00718.39
7.1.330.0100.00316.01
7.1.320.0000.02015.80
7.1.310.0000.01216.16
7.1.300.0000.01715.95
7.1.290.0030.00515.82
7.1.280.0070.00716.10
7.1.270.0040.01316.13
7.1.260.0090.01015.99
7.1.250.0160.00416.09
7.1.240.0100.00615.91
7.1.230.0090.00315.82
7.1.220.0080.00815.86
7.1.210.0040.00815.95
7.1.200.0040.00816.19
7.1.190.0030.00615.80
7.1.180.0040.00715.79
7.1.170.0080.00516.13
7.1.160.0000.01616.18
7.1.150.0060.00615.96
7.1.140.0090.00615.89
7.1.130.0100.00316.16
7.1.120.0000.00815.84
7.1.110.0050.00516.11
7.1.100.0050.01017.28
7.1.90.0060.00616.04
7.1.80.0060.00315.75
7.1.70.0020.01016.79
7.1.60.0030.01317.72
7.1.50.0130.00916.53
7.1.40.0060.00316.03
7.1.30.0030.00615.93
7.1.20.0000.01215.96
7.1.10.0000.01415.95
7.1.00.0020.04619.19
7.0.330.0120.00815.51
7.0.320.0070.01015.70
7.0.310.0000.01115.50
7.0.300.0040.00415.65
7.0.290.0130.00015.49
7.0.280.0070.00415.40
7.0.270.0030.00915.61
7.0.260.0040.00815.49
7.0.250.0050.00515.58
7.0.240.0040.00415.54
7.0.230.0000.01415.68
7.0.220.0040.01115.72
7.0.210.0050.00515.52
7.0.200.0060.00216.23
7.0.190.0120.00315.57
7.0.180.0030.00715.69
7.0.170.0030.00715.43
7.0.160.0030.00915.74
7.0.150.0070.01015.37
7.0.140.0020.04118.83
7.0.130.0070.00715.35
7.0.120.0100.00715.71
7.0.110.0070.00315.70
7.0.100.0100.04917.76
7.0.90.0120.03217.93
7.0.80.0010.04617.79
7.0.70.0050.02917.80
7.0.60.0070.03417.81
7.0.50.0070.03217.96
7.0.40.0080.02416.83
7.0.30.0100.04016.90
7.0.20.0080.02716.88
7.0.10.0020.03916.88
7.0.00.0030.04116.96
5.6.400.0100.01014.86
5.6.390.0030.01014.75
5.6.380.0060.01214.82
5.6.370.0040.01114.30
5.6.360.0040.00814.71
5.6.350.0030.00914.71
5.6.340.0000.01314.79
5.6.330.0030.00914.60
5.6.320.0100.00614.89
5.6.310.0070.00714.93
5.6.300.0040.01114.65
5.6.290.0060.00614.84
5.6.280.0070.04017.99
5.6.270.0060.01214.60
5.6.260.0070.01314.68
5.6.250.0070.02817.63
5.6.240.0050.04117.59
5.6.230.0120.04017.55
5.6.220.0030.04717.68
5.6.210.0090.03517.69
5.6.200.0050.02517.98
5.6.190.0070.04018.04
5.6.180.0070.03717.96
5.6.170.0030.03217.83
5.6.160.0100.03817.79
5.6.150.0030.04817.83
5.6.140.0030.02817.88
5.6.130.0100.04217.96
5.6.120.0120.03717.82
5.6.110.0020.03217.91
5.6.100.0070.02817.78
5.6.90.0030.03317.70
5.6.80.0050.04617.64
5.6.70.0070.04117.49
5.6.60.0090.04017.62
5.6.50.0070.02917.53
5.6.40.0080.03517.43
5.6.30.0030.04817.50
5.6.20.0090.02017.42
5.6.10.0050.03917.47
5.6.00.0080.02317.57
5.5.380.0130.04017.71
5.5.370.0100.02717.42
5.5.360.0030.03717.64
5.5.350.0070.04117.55
5.5.340.0120.04117.69
5.5.330.0060.03117.78
5.5.320.0080.03517.79
5.5.310.0080.04017.66
5.5.300.0100.04217.57
5.5.290.0100.03817.85
5.5.280.0040.04517.75
5.5.270.0080.04317.60
5.5.260.0080.02517.71
5.5.250.0070.04617.45
5.5.240.0120.02517.48
5.5.230.0110.04017.50
5.5.220.0070.04217.34
5.5.210.0060.04617.41
5.5.200.0160.03417.52
5.5.190.0060.03317.36
5.5.180.0120.03517.30
5.5.170.0030.01314.46
5.5.160.0070.04017.47
5.5.150.0070.04217.45
5.5.140.0090.02217.44
5.5.130.0120.03917.39
5.5.120.0070.03817.37
5.5.110.0080.03817.44
5.5.100.0070.03917.39
5.5.90.0080.02217.36
5.5.80.0100.03517.28
5.5.70.0100.04017.20
5.5.60.0080.04117.32
5.5.50.0070.04017.42
5.5.40.0030.04517.29
5.5.30.0080.04017.41
5.5.20.0060.04817.19
5.5.10.0100.03817.32
5.5.00.0080.03717.30
5.4.450.0110.03715.40
5.4.440.0110.04215.37
5.4.430.0080.02315.51
5.4.420.0030.03415.33
5.4.410.0030.03815.47
5.4.400.0030.04715.11
5.4.390.0120.03815.16
5.4.380.0050.02615.38
5.4.370.0070.03514.94
5.4.360.0050.03915.18
5.4.350.0020.04215.24
5.4.340.0070.03815.31
5.4.330.0040.00411.37
5.4.320.0050.02515.06
5.4.310.0070.02915.20
5.4.300.0040.03115.26
5.4.290.0020.04115.24
5.4.280.0030.03715.15
5.4.270.0080.02215.11
5.4.260.0030.04315.09
5.4.250.0090.03715.35
5.4.240.0070.02515.17
5.4.230.0090.02815.25
5.4.220.0030.02515.23
5.4.210.0060.03915.15
5.4.200.0040.03715.20
5.4.190.0050.03915.22
5.4.180.0050.02015.25
5.4.170.0050.04214.97
5.4.160.0000.04514.91
5.4.150.0070.02315.14
5.4.140.0020.03613.90
5.4.130.0050.03713.80
5.4.120.0010.02213.88
5.4.110.0030.03313.94
5.4.100.0060.03913.73
5.4.90.0050.03213.85
5.4.80.0050.02613.89
5.4.70.0080.03613.84
5.4.60.0070.03713.76
5.4.50.0050.03813.86
5.4.40.0070.03813.88
5.4.30.0100.03513.79
5.4.20.0050.04313.75
5.4.10.0020.04013.79
5.4.00.0090.03213.42
5.3.290.0030.04012.78
5.3.280.0080.03412.74
5.3.270.0020.03712.66
5.3.260.0030.02712.75
5.3.250.0090.02212.76
5.3.240.0070.03612.70
5.3.230.0050.04212.77
5.3.220.0020.02512.74
5.3.210.0050.03012.77
5.3.200.0050.03512.75
5.3.190.0090.03012.72
5.3.180.0050.04012.73
5.3.170.0110.03512.69
5.3.160.0090.03212.75
5.3.150.0070.03212.61
5.3.140.0050.03012.78
5.3.130.0080.03212.73
5.3.120.0070.03712.70
5.3.110.0050.02512.72
5.3.100.0070.02312.45
5.3.90.0070.03212.48
5.3.80.0030.02712.38
5.3.70.0080.04012.26
5.3.60.0100.03612.52
5.3.50.0020.04212.38
5.3.40.0080.03812.22
5.3.30.0020.02912.36
5.3.20.0040.04212.24
5.3.10.0050.03012.06
5.3.00.0010.02812.07

preferences:
31.98 ms | 401 KiB | 5 Q