AX2012 正则表达式返回所有匹配的Match对象

static void TestMatches(Args _args)
{
    System.Text.RegularExpressions.MatchCollection  regExMatchs;
    System.Text.RegularExpressions.Match            regExMatch;
    System.Collections.IEnumerator                  matchesEnum;
    
    Str1260                                         strings, pattern, result;
    int                                             matchCount;
    container                                       resultCon;
    ;
    
    strings = "A1B2C3D4";
    pattern = @"\d+";
    
    regExMatchs = System.Text.RegularExpressions.Regex::Matches(strings, pattern);
    
    matchCount = regExMatchs.get_Count();
    matchesEnum = regExMatchs.GetEnumerator();
    while (matchesEnum.MoveNext())
    {
        regExMatch = matchesEnum.get_Current();
        result = regExMatch.get_Value();
        if(!conFind(resultCon, result))
        {
            resultCon += [result];
        }
    }

    info(strFmt("Count: %1; Result: %2", matchCount, con2Str(resultCon)));
    // Count: 4; Result: 1,2,3,4
}

 

posted @ 2023-10-13 14:39  一口一个小馒头  阅读(10)  评论(0编辑  收藏  举报