title: Regex matching only a portion of string
body: <p>I would like to match a portion of a URL in this order. </p>
  
  <p>First the domain name will remain static. So, nothing check with regex. </p>
  
  <pre><code>$domain_name = "http://foo.com/"; 
  </code></pre>
  
  <p>What I would like to validate is what comes after the last <code>/</code>. </p>
  
  <p>So, my AIM is to create something like. </p>
  
  <pre><code>$stings_only            = "[\w+]";
  $number_only            = "[\d+]";
  $numbers_and_strings    = "[0-9][a-z][A-Z]"; 
  </code></pre>
  
  <p>Now, I would like to just use the above variables to check if a URL confirms to the patterns mentioned. </p>
  
  <pre><code>$example_url = "http://foo.com/some-title-with-id-1"; 
  
  var_dump(preg_match({$domain_name}{$strings_only}, $example_url)); 
  </code></pre>
  
  <p>The above should return false, because title is NOT $string_only. </p>
  
  <pre><code>$example_url = "http://foo.com/foobartar"; 
  
  var_dump(preg_match({$domain_name}{$strings_only}, $example_url)); 
  </code></pre>
  
  <p>The above should return true, because title is $string_only. </p>