title: Regex lookbehind alternative for Safari
body: <p>I have implemented this regex for matching a string for validation purposes:
  <code>^(?&lt;serialCode&gt;[a-zA-Z0-9]{0,3})(?:(?&lt;serialMarket&gt;[a-zA-Z]{1,2})(?&lt;serialSuffix&gt;(?&lt;=^.{5})[a-zA-Z0-9]*)?)?</code></p>
  <p>I'm using it in JS using <code>match()</code> function like this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const regex = '^(?&lt;serialCode&gt;[a-zA-Z0-9]{0,3})(?:(?&lt;serialMarket&gt;[a-zA-Z]{1,2})(?&lt;serialSuffix&gt;(?&lt;=^.{5})[a-zA-Z0-9]*)?)?';
  const stringToMatch = 'EV1FOO12FF344';
  const result = stringToMatch.match(new RegExp(regex));
  console.log(result); // returns each group for match and also the full match</code></pre>
  </div>
  </div>
  </p>
  <p>What basically this does is that it's doing the following step by step validations and creating groups:</p>
  <ul>
  <li>first 3 characters should be only alphanumeric characters</li>
  <li>characters 4 and 5 should be only letters</li>
  <li>all the rest of the characters should be alphanumeric characters</li>
  </ul>
  <p>This validation is done for every typed value in an input field, <strong>character by character</strong>.</p>
  <p>Using lookbehind as you can see above, this works perfectly for my purposes in Chrome and Mozilla Firefox browsers.</p>
  <p><strong>The problem</strong>: <code>lookbehind</code>(in current case <code>(?&lt;=^.{5})</code>) is not supported on Safari browser as per this link: <a href="https://caniuse.com/js-regexp-lookbehind" rel="nofollow noreferrer">https://caniuse.com/js-regexp-lookbehind</a> We receive this error in this case: <code>Invalid regular expression: invalid group specifier name</code></p>
  <p>Is there any alternative to that lookbehind so the regex will work in the exact same way?</p>
  <p>I have the link where I tested some values for exemplification: <a href="https://regex101.com/r/fPmiTk/1" rel="nofollow noreferrer">https://regex101.com/r/fPmiTk/1</a>
  There you can see how the strings are matched and how the groups are created.</p>