How can I extract a string between matching braces in Perl?

前端 未结 7 832
再見小時候
再見小時候 2020-12-06 06:19

My input file is as below :

HEADER 
{ABC|*|DEF {GHI 0 1 0} {{Points {}}}}

{ABC|*|DEF {GHI 0 2 0} {{Points {}}}}

{ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{         


        
7条回答
  •  盖世英雄少女心
    2020-12-06 06:59

    Regular expressions are actually pretty bad for matching braces. Depending how deep you want to go, you could write a full grammar (which is a lot easier than it sounds!) for Parse::RecDescent. Or, if you just want to get the blocks, search through for opening '{' marks and closing '}', and just keep count of how many are open at any given time.

提交回复
热议问题