private static StringPointer endCapture ( MatchState ms, StringPointer s, StringPointer p ) {
        int l = captureToClose ( ms );
        StringPointer res;
        ms.capture[l].len = ms.capture[l].init.length () - s.length ();  /* close capture */
        if ( ( res = match ( ms, s, p ) ) == null ) /* match failed? */ {
            ms.capture[l].len = CAP_UNFINISHED;  /* undo capture */
        }
        return res;
    }
Only works with non-negative numbers
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java