Shortest Pattern Match
Hi all, I believe vim carries out greedy pattern matching, i.e. the longest pattern found will be used. Is there a way of performing shortest matching ? As an example, I have the following text: fe fi fo united kingdom fe fi fo 0911 209 30 30 and I want to delete everything up to the word united so I used :%s/.*fo // but this deleted everything up to 0911. Thanks in advance, Bob
Re: Shortest Pattern Match
Hi, Bob Fleming wrote: Hi all, I believe vim carries out greedy pattern matching, i.e. the longest pattern found will be used. Is there a way of performing shortest matching ? As an example, I have the following text: fe fi fo united kingdom fe fi fo 0911 209 30 30 and I want to delete everything up to the word united so I used :%s/.*fo // but this deleted everything up to 0911. have a look at :help /\{ :%s/.\{-\}fo // Another way to remove everything in front of united is :%s/.*\zeunited// for the last united on the line and :%s/.\{-}\zeunited// for the first united (see :help /\ze for the special meaning of \ze) Regards, Jürgen -- Jürgen Krämer Softwareentwicklung HABEL GmbH Co. KGmailto:[EMAIL PROTECTED] Hinteres Öschle 2 Tel: +49 / 74 61 / 93 53 - 15 78604 Rietheim-WeilheimFax: +49 / 74 61 / 93 53 - 99
RE: [Bulk] Re: Shortest Pattern Match
Perfect, thanks very much. -Original Message- From: Jürgen Krämer [mailto:[EMAIL PROTECTED] Sent: Wed 12 July 2006 09:14 To: vim mailing list Subject: [Bulk] Re: Shortest Pattern Match Hi, Bob Fleming wrote: Hi all, I believe vim carries out greedy pattern matching, i.e. the longest pattern found will be used. Is there a way of performing shortest matching ? As an example, I have the following text: fe fi fo united kingdom fe fi fo 0911 209 30 30 and I want to delete everything up to the word united so I used :%s/.*fo // but this deleted everything up to 0911. have a look at :help /\{ :%s/.\{-\}fo // Another way to remove everything in front of united is :%s/.*\zeunited// for the last united on the line and :%s/.\{-}\zeunited// for the first united (see :help /\ze for the special meaning of \ze) Regards, Jürgen -- Jürgen Krämer Softwareentwicklung HABEL GmbH Co. KGmailto:[EMAIL PROTECTED] Hinteres Öschle 2 Tel: +49 / 74 61 / 93 53 - 15 78604 Rietheim-WeilheimFax: +49 / 74 61 / 93 53 - 99