home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!iWarp.intel.com|ichips!sedona!bhoughto
- From: bhoughto@sedona.intel.com (Blair P. Houghton)
- Subject: Re: A regexp quickie
- Message-ID: <1992Aug14.161834.8226@ichips.intel.com>
- Keywords: regexp.
- Sender: news@ichips.intel.com (News Account)
- Organization: Intel Corp., Chandler, Arizona
- References: <BsyqJs.HIz@cck.coventry.ac.uk>
- Date: Fri, 14 Aug 1992 16:18:34 GMT
- Lines: 29
-
- In article <BsyqJs.HIz@cck.coventry.ac.uk> ccx018@cch.coventry.ac.uk (Leslie Griffiths (Griff)) writes:
- >Its easy to express either of these
- >/^.*[ ]*/
- >and
- >/[ ][ ]*.*[ ][ ]*/
- >But how would one express both in a regexp.
- >NOTE - I am using sed, so no full regexps, no | or +
-
- sed is a cumulative process on a line. Do like so:
-
- sed -e '/^.*[ ]*/...' -e '>/[ ][ ]*.*[ ][ ]*/...'
-
- (where '...' is the action to be performed)
-
- However, your second pattern doesn't do the job. It
- gets the longest string matching the pattern, which
- includes all words between the first and last whitespace
- characters on the line. For instance, between these two
- upcarets:^ ^
-
- Come to look at it, your first pattern has the same
- problem; it matches everything up to the last word on the
- line.
-
- You want to omit whitespace from the inner part of the pattern.
- sed -e '/^[^ ]*[ ]*/...' -e '/[ ]*[^ ]*[ ]*/...'
-
- --Blair
- "Slam-bam-RTFM..."
-