title: PHP regular expression - match from start and end of string
body: <p>I used an online regular expression (regex) tester to build a simple regex, however using PHP's <a href="https://www.php.net/manual/en/function.preg-match.php" rel="nofollow noreferrer">preg_match</a> it's giving an unknown modifier for <code>$</code>.</p>
  <p>Here is the regex:</p>
  <pre><code>if (preg_match('/(^Keyword1/$|^Keyword2/$)/', $input, $matches))
  </code></pre>
  <p>I'm trying to check if <code>$input</code> equals either Keyword1/ or Keyword2/ (exact match). I know I can easily do this with &quot;if ($input == 'Keyword1/')&quot;, however I'd rather have a few lines of regex vs. a dozen <em>if</em> statements in the code.</p>
  <p>How can I fix it?</p>