# HG changeset patch # User pkienzle # Date 1018018146 0 # Node ID e81ae0798ca150654885da276512c063769904fd # Parent 190a32df8d0ccdeef371ac6de2684396417abee0 Fix returned indices so that they return the substring only diff -r 190a32df8d0c -r e81ae0798ca1 main/strings/regexp.cc --- a/main/strings/regexp.cc Wed Apr 03 06:48:31 2002 +0000 +++ b/main/strings/regexp.cc Fri Apr 05 14:49:06 2002 +0000 @@ -12,12 +12,15 @@ #include DEFUN_DLD(regexp,args,nargout,"\ +Regular expression string matching.\n\ match = regexp(pattern,string)\n\ Returns the start and end indices of the matching substring, or the\n\ or the empty matrix if there is none. There is one additional row\n\ for each set of parentheses in the pattern indicating the start and\n\ - end index for the first match for that subexpression.\n\ - Note that parentheses within ( exp1 | exp2 | ... ) are not counted.\n\ + end index for the first match for that subexpression. So the\n\ + expression string(match(2,1):match(2,2)) will return the string\n\ + matched by the first set of parentheses. Note that parentheses\n\ + within ( exp1 | exp2 | ... ) are not counted.\n\ [match s1 s2 ...] = regexp(pattern,string)\n\ Returns the matching substrings in s1, s2, etc.\n\ If there is no match then empty strings are returned.\n\ @@ -97,7 +100,7 @@ // Copy the match indices to retval(0) Matrix indices(matches,2); for (int i=0 ; i < subexpr && match[i].rm_so >= 0; i++) - indices(i,0) = match[i].rm_so+1, indices(i,1) = match[i].rm_eo+1; + indices(i,0) = match[i].rm_so+1, indices(i,1) = match[i].rm_eo; retval(0) = indices; // Copy the substrings to the output arguments