title: Regular Expression preg_match() for hreflang
body: <p>I'm working on <code>php script</code> to output a number of <code>hreflang</code> tags based on the page the user is on. Currently I am using <code>preg_match()</code> to match the URL being requested again a specific pattern. If it matches output the relevant tags...</p>
  
  <p>So I've got something like this:</p>
  
  <pre><code>&lt;?php if (preg_match("/^\/en-gb\/company/i", $url)): ?&gt;
      &lt;link rel="alternate" href="https://www.mydomain1.com/en-gb/company/" hreflang="en-gb" /&gt;
      &lt;link rel="alternate" href="https://www.mydomain1.com/company/" hreflang="en" /&gt;
      &lt;link rel="alternate" href="https://www.mydomain1.com/company/" hreflang="x-default" /&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>when I visit the page <code>www.mydomain1.com/en-gb/company</code> it outputs the  above tags. I also have another URL <code>www.mydomain1.com/en-gb/company/stats</code>. So I wrote another block for this URL:</p>
  
  <pre><code>   &lt;?php if (preg_match("/^\/en-gb\/company\/stats/i", $url)): ?&gt;
          &lt;link rel="alternate" href="https://www.mydomain1.com/en-gb/company/stats" hreflang="en-gb" /&gt;
          &lt;link rel="alternate" href="https://www.mydomain1.com/company/stats" hreflang="en" /&gt;
          &lt;link rel="alternate" href="https://www.mydomain1.com/company/stats" hreflang="x-default" /&gt;
      &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>However this page will output all of the <code>hreflangtags</code>from the first <code>if statement</code> and never enters the second. I know my <code>regular Expression</code> is wrong but I can't pinpoint exactly where. I'd appreciate any help in order to resolve.</p>