Saturday, May 29, 2010

Re: Regex matching the first occurrence of a string

ShayAllen wrote:
> I want to match everything between and including Begin and End. There are
> several blocks in the file:
>
> Begin
> ssss
> dfsdfsdf
> sdfsdf
> End
>
> Begin
> sasdfsa
> sdfgsd
> hghfgh
> End
>
> My best guess so far:
> :%s/Begin\_.*\(End\)\{-1}/This was one block/

Try this...
%s/^Begin\_$\_.\{-}\_^End$/This was one block/

:help /\{
:help /\_$
:help /\_^

Note that in your pattern, the \{-1} was modifying "End", which I don't
think is what you wanted.

Brett Stahlman

> Doesn't work
>
> What am I missing?
> Thanks.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment