bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: succinct awk code to check for paired parantheses?


From: Manuel Collado
Subject: Re: succinct awk code to check for paired parantheses?
Date: Thu, 25 Mar 2021 11:01:50 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

El 25/03/2021 a las 7:33, Wolfgang Laun escribió:
...
I had been thinking along similar lines. As I always try to reduce the
use of escaping, I came up with:

function isBalanced(s){
    gsub( /[^][)(}{]+/, "", s );       # only ']' is tricky in [...]
    while( gsub( /\(\)|{}|\[]/, "", s ) );   # an empty {} is not
"magic", and neither are unbalanced ']' and ')'
    return length(s) == 0;
}

Excellent! This is probably the minimal code that solves the problem.

Thanks.
--
Manuel Collado - http://mcollado.z15.es



reply via email to

[Prev in Thread] Current Thread [Next in Thread]