C# Regex.Match curly brackets- contents only? (exclude braces)

前端 未结 7 975
难免孤独
难免孤独 2020-12-01 12:17

I\'ve been unable to find an answer on this: can I use the Regex.Matches method to return only the contents of items with curly braces?

If I us

7条回答
  •  难免孤独
    2020-12-01 13:02

    Thanks Milosz Krajewski, Nothing to add but here is the function

    private List GetTokens(String str)
    {
        Regex regex = new Regex(@"(?<=\{)[^}]*(?=\})", RegexOptions.IgnoreCase);
        MatchCollection matches = regex.Matches(str);
    
        // Results include braces (undesirable)
        return matches.Cast().Select(m => m.Value).Distinct().ToList();
    }
    

提交回复
热议问题