匹配花括号内的内容

Input: {abc},   Output:  abc

正则表达式: (?<=\{)[^}]*(?=\})

(?<=\{)   匹配以左花括号开头
[^}]*    取得内容
(?=\})   匹配以右花括号结束

private List<String> GetTokens(String str)
{
    Regex regex = new Regex(@"(?<=\{)[^}]*(?=\})", RegexOptions.IgnoreCase);
    MatchCollection matches = regex.Matches(str);

    // Results include braces (undesirable)
    return matches.Cast<Match>().Select(m => m.Value).Distinct().ToList();
}

参考: http://stackoverflow.com/a/16538131/701457

相关文章:

  • 2022-02-16
  • 2022-02-07
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-02-07
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案