Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!viusys!uxui!unislc!ttobler From: ttobler@unislc.uucp (Trent Tobler) Newsgroups: comp.lang.c Subject: Re: pattern/wild card matching Message-ID: <1991Feb17.234654.25900@unislc.uucp> Date: 17 Feb 91 23:46:54 GMT References: <2953@cirrusl.UUCP> Organization: unisys Lines: 33 From article <2953@cirrusl.UUCP>, by dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi): > All the code referred to or posted seems to pay no special attention to > the "/" character, which in a UNIX environment has special meaning. It > would be really nice if code were available that would do the following > things: > > 1. Either require "/" to be explicitly matched or allow it to be > matched by wildcards. For example, * would match any character > sequence except slash, but ** would match any character sequence. > > 2. Allow the C-shell brace notation for grouping, i.e., {a,b,c}d in a > pattern would match any of ad, bd, and cd in the filename. > > I found Karl Heuer's posted code very useful, but it would be even > nicer if somebody had a canned routine that includes the above > features. If the code he posted follows grep style matching, all of the above is possible using the '[ ... ]' construct. For example, to match any character except a "/", use "[^/]", ie.. "m[^/]*/abc" will match "me/abc", "mirth/abc", etc. In number 2, instead of "{a,b,c}d", use "[abc]d". Of course, one drawback to this is that grep doesn't allow alternate strings of characters (at least as far as I know.) For example, the syntax I have seen used is "I will( | not )sleep" should match either "I will sleep", or "I will not sleep". -- Trent Tobler - ttobler@csulx.weber.edu