title: Find out the position where a regular expression failed
body: <p>I'm trying to write a lexer in JavaScript for finding tokens of a simple domain-specific language. I started with a simple implementation which just tries to match subsequent regexps from the current position in a line to find out whether it matches some token format and accept it then.</p>
  
  <p>The problem is that when something doesn't match inside such regexp, the whole regexp fails, so I don't know which character exactly caused it to fail.</p>
  
  <p>Is there any way to find out the position in the string which caused the regular expression to fail?</p>
  
  <p>INB4: I'm not asking about debugging my regexp and verifying its correctness. It is correct already, matches correct strings and drops incorrect ones. I just want to know programmatically where exactly the regexp stopped matching, to find out the position of a character which was incorrect in the user input, and how much of them were OK.</p>
  
  <p>Is there some way to do it with just simple regexps instead of going on with implementing a full-blown finite state automaton?</p>