Path: utzoo!attcan!uunet!wyse!vsi1!apple!bloom-beacon!tut.cis.ohio-state.edu!daemon From: jgreely@oz.cis.ohio-state.edu (J Greely) Newsgroups: comp.sources.d Subject: Re: PD version of "gmatch"? Message-ID: <24641@tut.cis.ohio-state.edu> Date: 14 Oct 88 14:31:41 GMT Sender: daemon@tut.cis.ohio-state.edu Lines: 29 In article <3286@ttidca.TTI.COM> Steve Alter (alter@ttidca.tti.com) writes: >Can someone point me to a public-domain (or at least legally copyable) >version of the "gmatch" routine? No, but I've got a quick substitute. >and the function returns non-zero if the string fits the pattern. The >pattern may contain '*', '?', or '[a-z]' style constructs. You've all >seen this before; >I'm just clarifying this to tell it apart from >regular expressions, which are entirely different beasts. Only in syntax. And it's easy to transform between the two. Use the regex package (Berkeley calls them re_comp and re_exec). In your pattern string, replace '?' with '.', '*' with '.*', and '[a-z]' with itself. re_exec will return 1 if the string matched the most recently compiled pattern. If you're going to use the same pattern frequently, you'll probably (ok, definitely) want to compile it outside your gmatch routine for efficiency. Don't have a good regex package? Look in comp.sources.unix, volume 7 (if you don't have an archive site nearby, I can send it to you). -- J Greely (jgreely@cis.ohio-state.edu; osu-cis!cis.ohio-state.edu!jgreely) "The motto of the place is 'Knowledge in pursuit of excellence'. Not truth, not beauty, not art or science. Just excellence."