Last edit
Summary: Fixed.
Changed:
< The function 'match' sets RSTART to the index of each match and RLENGTH to its length, and returns 0 when no matches exist. To find the last match on a line, then, all that is necessary is to call it until it no longer finds matches, and take the final substring.
to
> The function 'match' sets RSTART to the index of each match and RLENGTH to its length, and returns 0 when no matches exist. To find the last match on a line, then, all that is necessary is to call it and remove the match until it no longer finds matches, and take the final match.
Added:
> line = substr(line, RSTART+RLENGTH)
The function 'match' sets RSTART to the index of each match and RLENGTH to its length, and returns 0 when no matches exist. To find the last match on a line, then, all that is necessary is to call it and remove the match until it no longer finds matches, and take the final match.
function lastmatch(re, line, result) { while(match(line, re)) { result = substr(line, RSTART, RLENGTH) line = substr(line, RSTART+RLENGTH) } return result }