Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Even you have around 1 500 lines, the problem you like to solve is per each line.</p> <p>If you are able to process the input <em>line by line</em> you have already reduced the problem by a fair amount.</p> <pre><code>$file = new SplFileObject($path); foreach ($file as $i =&gt; $line) { printf("#%'0-4d: %s\n", $i, $line); } </code></pre> <p>This is just an example, naturally, the regular expression engine itself can do something similar with it's multiline modifier (m). However if you do the foreach above, you could <code>break</code> directly for testing with the first line:</p> <pre><code>foreach ($file as $i =&gt; $line) { printf("#%'0-4d: %s\n", $i, $line); $pattern = '(^\d++ &lt;A NAME="([^"]++)"&gt;&lt;A HREF="xtrastats.html#Philip McRae"&gt;Philip McRae&lt;/A&gt; C L OK 58 71 69 49 33 89 71 45 48 69 50 35 32 61 21 3 787 000)$'; $r = preg_match($pattern, $line, $matches); if (FALSE === $r) { throw new Exception(sprintf("Regex failed (%d)", preg_last_error()); } if (!$r) { throw new Exception(sprintf("Pattern does not match.")); } var_dump($matches); if ($i &gt; 0) break; # exit foreach after X lines. } echo "Done.\n"; </code></pre> <p>As you can see in this example, the pattern is yet incomplete, but you work out from the full line replacing step by step.</p> <p>It also makes use of an anchor for the beginning of the string (<code>^</code>) and for the end of the string (<code>$</code>).</p> <p>It also makes use of possessive quantifiers (<code>+</code>) so that if those don't match, no backtracking occurs (similar to atomic grouping, but easier to write).</p> <p>Continue to improve your regular expression pattern step by step. If the regex does not compile, an exception is thrown. As well as when a line does not match.</p> <p>You should get your stuff done after some time, improve the error handling and create some stable an efficient code in the long run.</p>
 

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