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

前端 未结 7 920
难免孤独
难免孤独 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:12

    I always liked it explicit. So you can use "positive lookbehind" (?<=...) and "positive lookahead" (?=...) groups:

    (?<=\{)
    [^}]*
    (?=\})
    

    which means:

    • require opening curly bracket before match
    • collect text (of, course) - as commented before I may be [^{}]* as well
    • require closing curly bracket after match
    0 讨论(0)
提交回复
热议问题