Regex - is it possible to find overlaping groups?

前端 未结 1 877
無奈伤痛
無奈伤痛 2021-01-24 23:30

I\'m new to regex and just want to know if its possible to find \"overlaping\" groups in the matches.

assume the following string:

20122 0029431

相关标签:
1条回答
  • 2021-01-24 23:58

    Yes, if you use lookahead assertions in combination with capturing groups:

    Regex regexObj = new Regex(@"(?=(\d{4}\s\d{4}\s\d{4}))");
    Match matchResult = regexObj.Match(subjectString);
    while (matchResult.Success) {
        resultList.Add(matchResult.Groups[1].Value);
        matchResult = matchResult.NextMatch();
    } 
    
    0 讨论(0)
提交回复
热议问题