Re: Regexps from shell wildcards

kanze@us-es.sel.de (James Kanze)
Mon, 5 Apr 1993 11:21:54 GMT

          From comp.compilers

Related articles
Regexps from shell wilcards colas@opossum.inria.fr (1993-04-02)
Re: Regexps from shell wildcards imp@Boulder.ParcPlace.COM (Warner Losh) (1993-04-05)
Re: Regexps from shell wildcards kanze@us-es.sel.de (1993-04-05)
Re: Regexps from shell wildcards macrakis@osf.org (1993-04-05)
Re: Regexps from shell wildcards gnb@leo.bby.com.au (1993-04-06)
| List of all articles for this month |
Newsgroups: comp.compilers
From: kanze@us-es.sel.de (James Kanze)
Keywords: lex
Organization: Compilers Central
References: 93-04-012 93-04-018
Date: Mon, 5 Apr 1993 11:21:54 GMT

Warner Losh writes:


|> >Is there an algorithm to convert shell-expressions into regular
|> >expressions? (i.e. generate the string ".*[.]c" from the input "*.c")


|> It is fairly straightforward to do this conversion for /bin/sh. Just
|> change '*' to '.*' and quote all the meta characters that have no special
|> meaning in /bin/sh, but do in the regexp package you are using.


Plus, change '.' to '[.]', if not already in []'s, and '?' to '.'.
(Note that this will require some state to determine whether one is
already in []'s or not.)


|> However, if you wanted to do /bin/csh shell expressions, then you'll find
|> that things like "*.{c,C,H,h,cf}" cause problems and cause the output
|> string length to grow wildly.


What's wrong with "*.{c,C,H,h,cf}" becoming ".*[.]([c|C|H|h|cf)". In
sum, just replace "{}" with "()", and the commas within it with '|'.
The output string doesn't grow at all. (Of course, some of your older
regexp programs, like grep, can't handle '|'.)
--
James Kanze email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.