Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!mentor.cc.purdue.edu!j.cc.purdue.edu!ksb From: ksb@j.cc.purdue.edu (Kevin Braunsdorf) Newsgroups: comp.sources.wanted Subject: Re: pattern matching Message-ID: <9499@j.cc.purdue.edu> Date: 19 May 89 21:44:17 GMT References: <2414@cveg.uucp> <11733@well.UUCP> <20021@yoyodyne.mips.com.mips.COM> Reply-To: ksb@j.cc.purdue.edu (Kevin Braunsdorf) Organization: Purdue UNIX Group Lines: 68 In (MARK H BOTNER) wrote: >Can anybody help me with pattern matching? In <11733@well.UUCP> jef@helios.ee.lbl.gov (Jef Poskanzer) wrote: In <20021@yoyodyne.mips.com.mips.COM> koblas@mips.COM (David Koblas) wrote: >Similar to Jef Posaknzer's but understands '{' ... '}' syntax. Sadly neither of these two routines really emulate the shell filename globbing. Here is a list of (some) failed tests. # pat file ans comment ???? /foo no ? doesn't match a / ?* /foo no ? doesn't match a / /??????? /usr/foo no ? doesn't match a / ? / no ? doesn't match a / .? ./ no ? doesn't match a non-leading / ? . no ? doesn't match a leading . * / no * doesn't match a / *? /foo no * doesn't match a / /u/* /u/a/foo no * doesn't match a / /u* /u/foo no * doesn't match a / * . no * doesn't match a . [/,]foo /foo no ranges do not match / * .ksb no * doesn't match leading . /*b /.ksb no * doesn't match leading . ?ksb .ksb no ? doesn't match leading . /?ksb /.ksb no ? doesn't match leading . # and one questionable rule.... //ksb /ksb yes any # glob /'s matches a / /a//b /a/b yes any # glob /'s matches a / For exmple: glob("/bin/mail", "*") would return true under both of these; (IMHO) this is wrong. [ We need at least: glob("/bin/mail", "/*/*") to really match this file. ] BTW: (noting the ! lines below,) does anyone know why the shell does this? $ touch ga g. .a $ ls -a ./ ../ .a g. ga $ echo g? g. ga $ echo "g"? g. ga $ echo .? .. .a ! $ echo "."? ! .? $ exit The `?' is not quoted in the last case... ? I will post my glob routines (which I think work) soon. -- "Time, time, time, see what's become of me..." kayessbee, Kevin Braunsdorf, ksb@j.cc.purdue.edu, pur-ee!ksb, purdue!ksb