Path: utzoo!utgpu!watserv1!watmath!att!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!csus.edu!ucdavis!sunny!poage From: poage@sunny.ucdavis.edu (Tom Poage) Newsgroups: comp.lang.perl Subject: Re: Matching parentheses Message-ID: <582@sunny.ucdavis.edu> Date: 28 Nov 90 22:12:10 GMT References: <1990Nov28.150131.28981@ugle.unit.no> Reply-To: poage@sunny.ucdavis.edu (Tom Poage) Organization: UCDMC Clinical Engineering, Sacto., CA Lines: 27 In article <1990Nov28.150131.28981@ugle.unit.no> harald.alvestrand@elab-runit.sintef.no writes: >I have thought a long time about this, but I am sure there must be some >magic way to do it: >How can I write a pattern that matches (), ((())), ((())()), but NOT ((())? >That is, how do I get a balanced matching of parentheses? >(or quotes, for that matter...) > > > Harald Tveit Alvestrand >Harald.Alvestrand@elab-runit.sintef.no >C=no;PRMD=uninett;O=sintef;OU=elab-runit;S=alvestrand;G=harald >+47 7 59 70 94 How about #!/bin/perl for ('()','((()))','((())())','((())') { if (tr/(/(/ != tr/)/)/) { warn "unmatched parentheses '$_'\n"; } } Tom. -- Tom Poage, Clinical Engineering Universiy of California, Davis, Medical Center, Sacramento, CA poage@sunny.ucdavis.edu {...,ucbvax,uunet}!ucdavis!sunny!poage