title: Partial matching a string against a regex
body: <p>Suppose that I have this regular expression: /abcd/
  Suppose that I wanna check the user input against that regex and disallow entering invalid characters in the input. When user inputs "ab", it fails as an match for the regex, but I can't disallow entering "a" and then "b" as user can't enter all 4 characters at once (except for copy/paste). So what I need here is a partial match which checks if an incomplete string can be potentially a match for a regex.</p>
  
  <p>Java has something for this purpose: <code>.hitEnd()</code> (described here <a href="http://glaforge.appspot.com/article/incomplete-string-regex-matching" rel="noreferrer">http://glaforge.appspot.com/article/incomplete-string-regex-matching</a>) python doesn't do it natively but has this package that does the job: <a href="https://pypi.python.org/pypi/regex" rel="noreferrer">https://pypi.python.org/pypi/regex</a>.</p>
  
  <p>I didn't find any solution for it in js. It's been asked years ago: <a href="https://stackoverflow.com/questions/9060979/javascript-regex-partial-match">Javascript RegEx partial match</a>
  and even before that: <a href="https://stackoverflow.com/questions/416425/check-if-string-is-a-prefix-of-a-javascript-regexp">Check if string is a prefix of a Javascript RegExp</a></p>
  
  <p>P.S. regex is custom, suppose that the user enters the regex herself and then tries to enter a text that matches that regex. The solution should be a general solution that works for regexes entered at runtime.</p>