pattern/wild card matching
Trent Tobler
ttobler at unislc.uucp
Mon Feb 18 10:46:54 AEST 1991
>From article <2953 at cirrusl.UUCP>, by dhesi%cirrusl at 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 at csulx.weber.edu
More information about the Comp.lang.c
mailing list