[comp.editors] Regular Expression

sgilley@cbnewsl.att.com (The Idealistic Cynic) (03/29/91)

Can a single regular expression be used to delete
all characters including and after the last "."
in a line?

Input might be:

test
stay.c
junk.1.c

And I need the output to be:

test
stay
junk.1

I've played with this a while, and can't seem to come
up with an answer that will work. (It's easy if you
assume all lines will have at least one "." in them..
what I can't get is if they don't.)

Thanks,

Sean.

---
Sean L. Gilley
attmail!mycroft!slg  attmail!sgilley
201 805 9088 (h)    201 457 5403 (w)

FFAAC09@cc1.kuleuven.ac.be (Nicole Delbecque & Paul Bijnens) (03/29/91)

In article <1991Mar28.191204.12295@cbnewsl.att.com>, sgilley@cbnewsl.att.com
(The Idealistic Cynic) says:
>
>Can a single regular expression be used to delete
>all characters including and after the last "." in a line?
>
>Input might be:
>
>test
>stay.c
>junk.1.c
>
>And I need the output to be:
>
>test
>stay
>junk.1
>
>I've played with this a while, and can't seem to come
>up with an answer that will work. (It's easy if you
>assume all lines will have at least one "." in them..
>what I can't get is if they don't.)

No need to assume there is a dot:

    :%s/\.[^.]*$//

in english:
    on all lines, substitute a literal dot, followed by anything
    but a dot, only at the end of a line, by nothing.
The substitution happens only on the lines that match.
Works with me (SYSV3.2 vi version 3.9 2/9/83).
--
Polleke   (Paul Bijnens)
Linguistics dept., K. University Leuven, Belgium
FFAAC09@cc1.kuleuven.ac.be

peter@ficc.ferranti.com (Peter da Silva) (03/30/91)

In article <1991Mar28.191204.12295@cbnewsl.att.com> sgilley@cbnewsl.att.com (The Idealistic Cynic) writes:
> Can a single regular expression be used to delete
> all characters including and after the last "."
> in a line?

{range}s/\.[^.]*$//

> (It's easy if you
> assume all lines will have at least one "." in them..
> what I can't get is if they don't.)

To avoid failure problems?

{range}g/\.[^.]*$/s///
-- 
Peter da Silva.  `-_-'  peter@ferranti.com
+1 713 274 5180.  'U`  "Have you hugged your wolf today?"