Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this regex in PHP actually work?
    primarykey
    data
    text
    <p>I am hoping the regular expression experts can tell me why this is going wrong:</p> <p>This regex:</p> <pre><code>$pattern = '/(?&lt;percent&gt;[0-9]{1,3}\.[0-9]{1,2})% of (?&lt;filesize&gt;.+) at/'; </code></pre> <p>Should match this sort of string:</p> <pre><code>[download] 87.1% of 4.40M at 107.90k/s ETA 00:05 [download] 89.0% of 4.40M at 107.88k/s ETA 00:04 [download] 91.4% of 4.40M at 106.09k/s ETA 00:03 [download] 92.9% of 4.40M at 105.55k/s ETA 00:03 </code></pre> <p>Correct? Is there anything that could go wrong with that regex that will not get it to match with the above input? Full usage here:</p> <pre><code>while(!feof($handle)) { $progress = fread($handle, 8192); $pattern = '/(?&lt;percent&gt;[0-9]{1,3}\.[0-9]{1,2})% of (?&lt;filesize&gt;.+) at/'; if(preg_match_all($pattern, $progress, $matches)){ //matched } } </code></pre> <p>Could how much that is being read by <strong>fread</strong> be effecting the regex to work correctly?</p> <p>I really need confirmation as I am trying to identify why it isn't working on a new server. This question is related to <a href="https://stackoverflow.com/questions/664332/change-in-server-permits-script-not-to-work-can-this-be-due-to-php-ini-being-dif">Change in Server Permits script not to work. Can this be due to PHP.ini being different?</a></p> <p>Thanks all</p> <h2>Update 2</h2> <p>I have made a test script to test the regex but even on its own it doesn't work??</p> <pre><code>&lt;?php error_reporting(E_ALL); echo 'Start'; $progress = "[download]75.1% of 4.40M at 115.10k/s ETA 00:09 [download] 77.2% of 4.40M at 112.36k/s ETA 00:09 [download] 78.6% of 4.40M at 111.41k/s ETA 00:08 [download] 80.3% of 4.40M at 110.80k/s ETA 00:07 [download] 82.3% of 4.40M at 110.30k/s ETA 00:07 [download] 84.3% of 4.40M at 108.33k/s ETA 00:06 [download] 85.7% of 4.40M at 107.62k/s ETA 00:05 [download] 87.5% of 4.40M at 107.21k/s ETA 00:05 [download] 89.5% of 4.40M at 105.10k/s ETA 00:04 [download] 90.7% of 4.40M at 106.45k/s ETA 00:03 [download] 93.2% of 4.40M at 104.92k/s ETA 00:02 [download] 94.8% of 4.40M at 104.40k/s ETA 00:02 [download] 96.5% of 4.40M at 102.47k/s ETA 00:01 [download] 97.7% of 4.40M at 103.48k/s ETA 00:01 [download] 100.0% of 4.40M at 103.15k/s ETA 00:00 [download] 100.0% of 4.40M at 103.16k/s ETA 00:00 "; $pattern = '/(?&lt;percent&gt;\d{1,3}\.\d{1,2})%\s+of\s+(?&lt;filesize&gt;[\d.]+[kBM]) at/'; if(preg_match_all($pattern, $progress, $matches)){ echo 'match'; } echo '&lt;br&gt;Done&lt;br&gt;'; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload