regexp question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

regexp question

Mathieu Zhang-2
I have this question working in vi, but I suppose it's
generally enought for all regexp.

How do I match across line? I would like to find the
end to a sentence by looking for \.$^[A-Z], but it
doesn't work. What is the correct way of match across
two different lines. In the same spirity, How should I
replace by inserting a \r or \n, i.e.

This is sentence one. This is sentence two.
becomes
This is sentence one.
This is sentence two.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: regexp question

A.J.Mechelynck
Ling F. Zhang wrote:

> I have this question working in vi, but I suppose it's
> generally enought for all regexp.
>
> How do I match across line? I would like to find the
> end to a sentence by looking for \.$^[A-Z], but it
> doesn't work. What is the correct way of match across
> two different lines. In the same spirity, How should I
> replace by inserting a \r or \n, i.e.
>
> This is sentence one. This is sentence two.
> becomes
> This is sentence one.
> This is sentence two.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 
>
>
>  
Most wildcards won't match linebreaks. Add an underscore for that (for
instance, to match across linebreaks until the last X in the file, match
for \_.*X ). To match a linebreak and nothing else, match for \n -- but
to _insert_ a line break, include \r in the "replace by" string.

Note that $ in the "replace what" pattern will only match an end-of-line
if it is at the end of the pattern. Elsewhere, it matches a dollar sign.

To replace "a period followed by a space" by "a period followed by a
linebreak" everywhere in the file, use

    :1,$s/\. /\.\r/g

(To replace it only in the current line, omit the 1,$ range. To replace
only the first occurrence, omit the /g at the end.) Note that to match a
period you must use \. because just . matches "any character but not a
linebreak".

see
    :help :s
    :help /multi
    :help /ordinary-atom
    :help sub-replace-special

and what they resend to.


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: regexp question

Kyku-2
In reply to this post by Mathieu Zhang-2
Ling F. Zhang wrote:
> I have this question working in vi, but I suppose it's
> generally enought for all regexp.
>
> How do I match across line? I would like to find the
> end to a sentence by looking for \.$^[A-Z], but it
> doesn't work. What is the correct way of match across
> two different lines.
How about   \.\_s*[A-Z]   - this should match inner ends of sentences
too? It also looks that \.\n[A-Z] works, too.
> In the same spirity, How should I
> replace by inserting a \r or \n, i.e.
>
> This is sentence one. This is sentence two.
> becomes
> This is sentence one.
> This is sentence two.
>  
In substitution pattern press Ctr-V and then Enter. It should be
replaced by something like ^M, i.e:

:%s/\.\s\+\([A-Z]\)/.^M\1/gc