Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!bionet!agate!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!munnari!basser!john From: john@basser.oz (John Mackin) Newsgroups: comp.sources.d Subject: Re: PD version of "gmatch"? Summary: it's not trivial to do it with a regular expression matcher Message-ID: <1555@basser.oz> Date: 23 Oct 88 06:39:52 GMT References: <24641@tut.cis.ohio-state.edu> Reply-To: john@basser.oz (John Mackin) Organization: Dept of Comp Sci, Uni of Sydney, Australia Lines: 32 In article <24641@tut.cis.ohio-state.edu>, jgreely@oz.cis.ohio-state.edu (J Greely) writes: > In article <3286@ttidca.TTI.COM> Steve Alter (alter@ttidca.tti.com) writes: > >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. Unfortunately, this doesn't work. You have neglected to consider the fact that the pattern given to gmatch may contain characters that are metacharacters to regex but not gmatch: .[]^$ spring to mind instantly. If it was just .^$ you could easily add \ in front of them, but character classes complicate it to where it's barely worth doing in my opinion, and when you start to consider the semantics of \ itself in the gmatch pattern, it's certainly no harder to just write gmatch than it is to translate a gmatch pattern into a regular expression. John Mackin, Basser Department of Computer Science, University of Sydney, Sydney, Australia john@basser.oz.AU (john%basser.oz.AU@UUNET.UU.NET) {uunet,mcvax,ukc,nttlab}!munnari!basser.oz!john