你需要使用偏移量,man regexec里
BYTE OFFSETS el
Unless REG_NOSUB was set for the compilation of the pattern buffer, it is possible to obtain substring match addressing information.
pmatch must be dimensioned to have at least nmatch elements. These are filled in by regexec() with substring match addresses. Any
unused structure elements will contain the value -1.
The regmatch_t structure which is the type of pmatch is defined in regex.h.
Each rm_so element that is not -1 indicates the start offset of the next largest substring match within the string. The relative
rm_eo element indicates the end offset of the match.