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()->compile()->match("all3");

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.0060.01518.92
8.3.50.0140.00521.39
8.3.40.0070.00719.04
8.3.30.0070.01619.17
8.3.20.0080.00020.46
8.3.10.0000.00822.08
8.3.00.0040.00420.89
8.2.180.0120.00317.13
8.2.170.0100.01022.96
8.2.160.0140.00719.13
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0150.00026.16
8.2.120.0050.00519.89
8.2.110.0100.00022.14
8.2.100.0120.00019.70
8.2.90.0060.00319.47
8.2.80.0030.00518.18
8.2.70.0080.00018.00
8.2.60.0030.00618.05
8.2.50.0080.00018.13
8.2.40.0060.00319.88
8.2.30.0030.00618.20
8.2.20.0040.00418.14
8.2.10.0030.00518.01
8.2.00.0060.00318.00
8.1.280.0070.00725.92
8.1.270.0050.00322.31
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0040.00423.83
8.1.230.0040.00718.96
8.1.220.0000.00817.77
8.1.210.0030.00618.77
8.1.200.0000.01017.60
8.1.190.0000.00817.76
8.1.180.0030.00518.86
8.1.170.0090.00018.84
8.1.160.0000.00722.31
8.1.150.0040.00418.99
8.1.140.0040.00417.61
8.1.130.0090.00017.90
8.1.120.0000.00717.69
8.1.110.0080.00317.63
8.1.100.0040.00417.67
8.1.90.0080.00017.67
8.1.80.0000.00817.76
8.1.70.0040.00417.68
8.1.60.0030.00517.83
8.1.50.0030.00617.64
8.1.40.0040.00417.70
8.1.30.0050.00317.86
8.1.20.0030.00517.88
8.1.10.0060.00317.83
8.1.00.0030.00617.71
8.0.300.0040.00418.77
8.0.290.0000.00817.30
8.0.280.0030.00518.61
8.0.270.0040.00417.44
8.0.260.0040.00417.16
8.0.250.0050.00317.29
8.0.240.0050.00317.15
8.0.230.0000.00817.18
8.0.220.0000.00717.05
8.0.210.0000.00817.19
8.0.200.0080.00017.27
8.0.190.0030.00617.25
8.0.180.0040.00417.13
8.0.170.0040.00417.22
8.0.160.0040.00417.21
8.0.150.0070.00017.04
8.0.140.0030.00617.09
8.0.130.0030.00313.61
8.0.120.0000.00917.11
8.0.110.0040.00417.04
8.0.100.0030.00517.14
8.0.90.0040.00417.24
8.0.80.0130.01017.07
8.0.70.0030.00617.17
8.0.60.0000.00817.20
8.0.50.0030.00517.24
8.0.30.0090.01217.19
8.0.20.0170.00217.55
8.0.10.0030.00617.11
8.0.00.0100.00916.96
7.4.330.0000.00515.07
7.4.320.0000.00716.76
7.4.300.0100.00016.95
7.4.290.0030.00516.86
7.4.280.0030.00316.79
7.4.270.0000.00716.76
7.4.260.0040.00416.86
7.4.250.0070.00016.68
7.4.240.0020.00616.92
7.4.230.0000.00716.93
7.4.220.0070.01016.77
7.4.210.0070.00716.86
7.4.200.0080.00016.99
7.4.190.0030.00316.72
7.4.160.0080.00816.80
7.4.150.0110.00717.40
7.4.140.0110.01017.86
7.4.130.0150.00516.81
7.4.120.0070.01116.99
7.4.110.0150.00316.90
7.4.100.0070.01116.97
7.4.90.0120.00616.79
7.4.80.0090.00919.39
7.4.70.0180.00016.79
7.4.60.0100.00616.93
7.4.50.0000.00516.70
7.4.40.0030.01322.77
7.4.30.0090.00916.76
7.4.10.0030.01415.32
7.4.00.0110.00815.44
7.3.330.0050.00013.63
7.3.320.0000.00513.53
7.3.310.0030.00316.67
7.3.300.0030.00316.54
7.3.290.0110.00616.62
7.3.280.0080.01116.68
7.3.270.0130.00417.40
7.3.260.0100.01016.67
7.3.250.0070.01416.81
7.3.240.0120.00716.79
7.3.230.0040.01416.84
7.3.210.0060.01216.92
7.3.200.0030.01319.39
7.3.190.0150.00816.70
7.3.180.0090.00916.79
7.3.170.0100.00716.84
7.3.160.0060.01116.89
7.3.130.0090.00915.18
7.3.120.0070.01015.02
7.3.110.0040.01515.25
7.3.100.0070.00715.20
7.3.90.0170.00315.03
7.3.80.0060.00615.26
7.3.70.0060.00615.25
7.3.60.0000.01415.09
7.3.50.0070.00315.03
7.3.40.0030.01015.17
7.3.30.0060.00315.15
7.3.20.0030.01016.90
7.3.10.0050.01116.83
7.3.00.0030.01017.00
7.2.330.0060.01216.87
7.2.320.0090.01217.05
7.2.310.0070.01016.96
7.2.300.0060.01016.96
7.2.290.0080.00916.83
7.2.260.0090.00915.56
7.2.250.0110.00715.42
7.2.240.0030.01015.50
7.2.230.0030.00615.43
7.2.220.0060.00915.36
7.2.210.0030.01015.55
7.2.200.0070.00715.46
7.2.190.0030.00815.09
7.2.180.0030.01315.28
7.2.170.0000.01015.16
7.2.160.0090.00615.39
7.2.150.0030.01517.37
7.2.140.0030.01317.24
7.2.130.0050.00917.19
7.2.120.0090.00517.18
7.2.110.0070.00617.10
7.2.100.0030.01217.24
7.2.90.0070.00816.97
7.2.80.0050.00917.08
7.2.70.0050.01117.20
7.2.60.0050.01117.00
7.2.50.0040.00917.18
7.2.40.0080.00617.14
7.2.30.0090.00717.18
7.2.20.0050.00917.13
7.2.10.0070.00817.20
7.2.00.0060.00817.95
7.1.330.0000.01616.19
7.1.320.0090.01216.11
7.1.310.0030.01015.95
7.1.300.0070.00715.90
7.1.290.0040.01116.00
7.1.280.0120.00615.96
7.1.270.0040.01115.97
7.1.260.0120.00616.14
7.1.250.0020.01116.08
7.1.240.0040.01116.02
7.1.230.0000.01115.92
7.1.220.0110.00615.92
7.1.210.0060.01215.82
7.1.200.0090.00415.89
7.1.190.0000.01815.92
7.1.180.0100.00016.04
7.1.170.0100.00316.15
7.1.160.0060.00315.95
7.1.150.0080.00815.90
7.1.140.0070.00716.02
7.1.130.0070.00715.91
7.1.120.0000.00916.11
7.1.110.0000.01716.17
7.1.100.0080.00517.08
7.1.90.0090.00915.83
7.1.80.0090.00415.68
7.1.70.0070.00716.73
7.1.60.0110.00917.90
7.1.50.0030.01016.64
7.1.40.0030.00616.10
7.1.30.0130.00316.05
7.1.20.0070.00416.03
7.1.10.0090.00615.97
7.1.00.0080.04319.22
7.0.330.0070.00715.48
7.0.320.0030.00615.66
7.0.310.0060.00915.54
7.0.300.0060.00615.33
7.0.290.0130.00315.45
7.0.280.0030.01015.62
7.0.270.0000.01415.49
7.0.260.0030.01015.83
7.0.250.0000.01315.40
7.0.240.0070.01015.68
7.0.230.0060.00315.67
7.0.220.0000.01615.39
7.0.210.0070.00715.68
7.0.200.0060.00716.21
7.0.190.0030.01015.57
7.0.180.0100.00715.81
7.0.170.0110.00315.76
7.0.160.0040.01115.70
7.0.150.0070.00715.29
7.0.140.0020.04418.96
7.0.130.0030.01015.50
7.0.120.0070.01115.55
7.0.110.0070.01015.44
7.0.100.0000.03217.83
7.0.90.0100.02017.91
7.0.80.0130.02517.89
7.0.70.0030.04617.94
7.0.60.0030.04517.85
7.0.50.0120.04718.05
7.0.40.0070.04816.85
7.0.30.0120.03916.93
7.0.20.0000.03016.91
7.0.10.0100.04016.86
7.0.00.0080.03116.68
5.6.400.0120.00614.58
5.6.390.0060.00614.23
5.6.380.0100.00714.44
5.6.370.0070.01014.65
5.6.360.0000.01014.90
5.6.350.0080.00815.05
5.6.340.0000.00914.67
5.6.330.0070.00714.82
5.6.320.0000.00914.86
5.6.310.0080.00614.55
5.6.300.0070.01014.73
5.6.290.0100.00314.60
5.6.280.0040.04317.91
5.6.270.0000.01614.49
5.6.260.0100.00714.69
5.6.250.0070.03517.69
5.6.240.0120.01917.65
5.6.230.0040.03817.61
5.6.220.0080.02717.74
5.6.210.0030.03217.58
5.6.200.0110.04317.79
5.6.190.0070.04217.77
5.6.180.0080.04517.68
5.6.170.0080.05017.79
5.6.160.0030.03317.72
5.6.150.0120.04017.71
5.6.140.0130.03517.87
5.6.130.0030.03118.02
5.6.120.0030.04417.62
5.6.110.0030.03817.96
5.6.100.0100.02517.74
5.6.90.0100.03817.92
5.6.80.0080.03917.49
5.6.70.0080.02617.59
5.6.60.0050.03617.47
5.6.50.0090.03817.46
5.6.40.0030.04517.60
5.6.30.0080.02117.44
5.6.20.0040.04517.58
5.6.10.0070.02617.67
5.6.00.0030.04317.64
5.5.380.0090.03817.69
5.5.370.0060.04817.50
5.5.360.0060.02317.56
5.5.350.0080.04117.54
5.5.340.0100.03517.87
5.5.330.0050.03017.82
5.5.320.0120.04017.84
5.5.310.0030.04517.74
5.5.300.0120.04217.92
5.5.290.0090.04117.76
5.5.280.0040.03117.68
5.5.270.0080.03717.68
5.5.260.0020.05117.71
5.5.250.0100.04017.74
5.5.240.0060.04117.59
5.5.230.0070.04017.40
5.5.220.0080.04217.30
5.5.210.0050.02917.40
5.5.200.0030.04117.29
5.5.190.0050.04617.36
5.5.180.0030.04417.35
5.5.170.0060.00914.64
5.5.160.0030.02517.29
5.5.150.0080.03317.53
5.5.140.0110.03917.45
5.5.130.0100.03817.46
5.5.120.0030.03017.33
5.5.110.0120.02717.47
5.5.100.0080.03017.38
5.5.90.0050.04817.37
5.5.80.0030.04217.35
5.5.70.0020.03217.39
5.5.60.0030.04617.44
5.5.50.0070.03217.32
5.5.40.0070.04317.42
5.5.30.0050.04617.39
5.5.20.0050.04317.42
5.5.10.0070.04217.37
5.5.00.0050.02917.16
5.4.450.0050.04515.77
5.4.440.0050.04315.71
5.4.430.0030.03315.80
5.4.420.0020.03915.70
5.4.410.0080.04015.59
5.4.400.0080.02315.45
5.4.390.0050.03815.54
5.4.380.0070.03615.64
5.4.370.0110.02815.57
5.4.360.0080.03815.58
5.4.350.0050.04015.54
5.4.340.0050.02215.54
5.4.330.0040.00412.04
5.4.320.0060.03115.57
5.4.310.0120.03415.62
5.4.300.0080.03215.53
5.4.290.0100.03815.61
5.4.280.0080.03215.45
5.4.270.0070.02315.63
5.4.260.0080.04015.60
5.4.250.0070.04015.58
5.4.240.0070.04115.44
5.4.230.0020.03215.47
5.4.220.0070.02515.60
5.4.210.0050.04015.44
5.4.200.0100.03015.61
5.4.190.0080.04015.62
5.4.180.0030.03715.63
5.4.170.0050.03815.54
5.4.160.0050.03415.44
5.4.150.0060.02215.45
5.4.140.0040.04514.28
5.4.130.0060.02714.31
5.4.120.0020.02714.17
5.4.110.0030.03314.28
5.4.100.0110.03814.29
5.4.90.0050.02014.22
5.4.80.0020.02714.24
5.4.70.0040.02014.28
5.4.60.0090.01414.22
5.4.50.0060.03614.17
5.4.40.0070.03814.29
5.4.30.0050.03614.25
5.4.20.0080.03614.21
5.4.10.0050.04014.16
5.4.00.0030.04013.98
5.3.290.0070.04013.42
5.3.280.0030.02813.35
5.3.270.0030.02713.37
5.3.260.0000.03813.39
5.3.250.0060.03013.39
5.3.240.0080.01813.41
5.3.230.0030.02213.33
5.3.220.0080.03813.35
5.3.210.0050.02213.32
5.3.200.0040.02113.35
5.3.190.0040.02913.37
5.3.180.0080.03513.35
5.3.170.0000.02613.39
5.3.160.0020.04113.30
5.3.150.0030.03013.33
5.3.140.0070.03013.35
5.3.130.0020.03813.39
5.3.120.0050.02813.30
5.3.110.0020.03413.33
5.3.100.0050.03313.08
5.3.90.0080.03113.07
5.3.80.0030.03713.12
5.3.70.0060.01613.13
5.3.60.0020.02013.01
5.3.50.0050.02412.98
5.3.40.0050.04113.06
5.3.30.0080.03213.07
5.3.20.0060.03612.98
5.3.10.0050.03912.88
5.3.00.0030.03512.82

preferences:
43.51 ms | 401 KiB | 5 Q