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

前端 未结 7 820
再見小時候
再見小時候 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 07:04

    I don't think pure regular expressions are what you want to use here (IMHO this might not even be parsable using regex).

    Instead, build a small parser, similar to what's shown here: http://www.perlmonks.org/?node_id=308039 (see the answer by shotgunefx (Parson) on Nov 18, 2003 at 18:29 UTC)

    UPDATE It seems it might be doable with a regex - I saw a reference to matching nested parentheses in Mastering Regular Expressions (that's available on Google Books and thus can be googled for if you don't have the book - see Chapter 5, section "Matching balanced sets of parentheses")

    0 讨论(0)
提交回复
热议问题