home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!caen!nic.umass.edu!news.amherst.edu!twpierce
- From: twpierce@unix.amherst.edu (Tim Pierce)
- Subject: Re: warning possible FAQ: not substring in regex
- Message-ID: <BxBtn0.DFo@unix.amherst.edu>
- Keywords: regular expression
- Organization: Homosexual Fascist Lobby, Rampant Paranoia Division
- References: <1992Nov7.003902.3217@u.washington.edu>
- Date: Sat, 7 Nov 1992 03:28:12 GMT
- Lines: 30
-
- In article <1992Nov7.003902.3217@u.washington.edu> godden@stein.u.washington.edu (Jeff Godden) writes:
-
- >How do you specify within a regular expression NOT a substring? That
- >is, suppose I want to find all filenames that begin with the letter
- >'z' and don't contain the string "cy" anywhere in them, is this possible?
- >If so how? Does this work?:
- >
- > ^z.*[^c][^y].*
-
- First of all, remember that filename globbing (as in `ls *.[ch]') uses
- a slightly different syntax from ed-style regular expressions, as with
- the example you give above. The only differences I can think of
- offhand, though, is that the `.' wildcard character is `?' in filename
- globbing, and the globbing metacharacter `*' will match any sequence
- of *any* character (it's equivalent to the regular expression `.*').
-
- The regular expression you describe above is not really what you're
- looking for. When I need to extract really complicated text patterns,
- I'll usually pipe into grep several times, like:
-
- ls | grep ^z | grep -v cy
-
- I wouldn't be surprised if this can be accomplished with tagged
- regexps or other nifty egrep features, but it's served me well in the
- past.
-
- --
- ____ Tim Pierce /
- \ / twpierce@unix.amherst.edu / I use antlers in all of my decorating.
- \/ (BITnet: TWPIERCE@AMHERST) /
-