in reply to Re: Can I determine index point of failure in string during regex match attempt
in thread Can I determine index point of failure in string during regex match attempt

For the case of a simple string of characters, that would be an easy way to handle it. And as Oiskuu mentioned below, full regex capability probably does essentially make this a variant of the Halting problem.

So perhaps a simpler question. Can you get the index of the last successful matching character for a failed regex? Judging from what I've seen, I don't think so, but I'm often wrong :)

  • Comment on Re^2: Can I determine index point of failure in string during regex match attempt

Replies are listed 'Best First'.
Re^3: Can I determine index point of failure in string during regex match attempt
by AnomalousMonk (Archbishop) on May 07, 2014 at 00:53 UTC

    My limited understanding of regex behavior is that the RE tries to match the regex  'aaaa' =~ /b/ everywhere, so the last 'failed' match position would always be at the end of the  'aaaa' string. (I believe that on-going regex optimization efforts have led to an RE that will abandon matching very quickly, perhaps not even start, if faced with such a simple regex as the one in the example. But as the regex begins to be even a little more complex, attempts at such optimizations are soon frustrated.)

    In the case of an anchored or unanchored regex, the RE must, of course, 'know' in some sense when and where matches fail, and where the last attempt ends. But since the RE is only concerned with reporting successful matches and not unsuccessful ones, of which there may be many and many, this information is not, as far as I am aware, preserved.

    In any event, it still seems to me that questions like "what is the last offset at which 'efg' matches in 'abcdefghi'?" or "what is the last offset at which 'abc' anchored at the start of 'abcdef' matches?" can easily be answered by index.