Begin
ssss
dfsdfsdf
sdfsdf
End
Begin
sasdfsa
sdfgsd
hghfgh
End
My best guess so far:
:%s/Begin\_.*\(End\)\{-1}/This was one block/
Doesn't work
What am I missing?
Thanks.
--
View this message in context: http://old.nabble.com/Regex-matching-the-first-occurrence-of-a-string-tp28712875p28712875.html
Sent from the Vim - General mailing list archive at Nabble.com.
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
Without details of what "Doesn't work" means, it's a little hard
to guess. Can your blocks be nested?
Begin
stuff
Begin
stuff2
stuff3
End
stuff4
End
Does case matter? Can you have begin/end text in other stuff?
Begin
stuff
this is not the End
more stuff
End
-tim
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/
> Doesn't work
>
> What am I missing?
> Thanks.
>
Fair questions, Tim. No nested blocks or other tricky stuff. Brett's
solution worked fine and was an instructive example for me. Thanks.
--
View this message in context: http://old.nabble.com/Regex-matching-the-first-occurrence-of-a-string-tp28712875p28725924.html