home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / question / 13062 < prev    next >
Encoding:
Text File  |  1992-11-08  |  1.7 KB  |  42 lines

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