Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_INTERNAL UText* U_EXPORT2 uregex_groupUText ( URegularExpression regexp,
int32_t  groupNum,
UText dest,
UErrorCode status 

Extract the string for the specified matching expression or subexpression. Group #0 is the complete string of matched text. Group #1 is the text matched by the first set of capturing parentheses.

regexp The compiled regular expression.
groupNum The capture group to extract. Group 0 is the complete match. The value of this parameter must be less than or equal to the number of capture groups in the pattern.
dest Mutable UText to receive the matching string data. If NULL, a new UText will be created (which may not be mutable).
status A reference to a UErrorCode to receive any errors.
The matching string data. If a pre-allocated UText was provided, it will always be used and returned.

For internal use only.

ICU 4.4 technology preview

Definition at line 659 of file uregex.cpp.


    RegularExpression *regexp = (RegularExpression*)regexp2;
    if (validateRE(regexp, status) == FALSE) {
        UErrorCode emptyTextStatus = U_ZERO_ERROR;
        return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus));

    if (regexp->fText != NULL) {
        // Pick up the range of characters from the matcher
        // and use our already-extracted characters
        int32_t  startIx = regexp->fMatcher->start(groupNum, *status);
        int32_t  endIx   = regexp->fMatcher->end  (groupNum, *status);
        if (U_FAILURE(*status)) {
            UErrorCode emptyTextStatus = U_ZERO_ERROR;
            return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus));
        if (dest) {
            utext_replace(dest, 0, utext_nativeLength(dest), &regexp->fText[startIx], endIx - startIx, status);
        } else {
            UText groupText = UTEXT_INITIALIZER;
            utext_openUChars(&groupText, &regexp->fText[startIx], endIx - startIx, status);
            dest = utext_clone(NULL, &groupText, TRUE, FALSE, status);
        return dest;
    } else {
        return regexp->fMatcher->group(groupNum, dest, *status);

Generated by  Doxygen 1.6.0   Back to index