On Sat, Oct 29, 2011 at 2:04 PM, Thilo Six <[email protected]> wrote: > Thilo Six wrote the following on 29.10.2011 16:07 > > hello, > > -- <snip> -- > >>> So, /vi\|vim is same as /vi. >> >> Thank you for the pointers. >> I need to mentally keep a note about that for future. > > > ,----[ :help regexp ]------------------------- > > If more than one branch matches, the first one is used. > `--------------------------------------------- > > I don't speak c, so why is there the limitation mentioned above? > It can't be for performance because both searches are equally fast (humanly > speaking).
This is a common design choice for regular expressions. The left-most pattern that matches is what is used. You'll see similar behavior with PCRE: $ printf "vim\n" | perl -pe '/(vi|vim)/ && print "$1\n"' vi > But it breaks expectations as i tell vim to search for 'vi' OR 'vim' > in both cases. > Maybe if i understand the technical background i get more used to it. In this specific example, sure it's not that much more work to use the longest of the two patterns as THE match, but this is a trivial case. You can have much more complicated patterns and multiple alternations. Then do you really want to have the regex engine try all the alternations just to find the one that's matches the most text and is that really what you want in that specific scenario? It's much easier to just change the regular expression to do what you want with the understanding of how regular expressions are used. I'd suggest the book "Mastering Regular Expressions". It does a pretty good job of explaining how various regular expression engines work and things to keep in mind when crafting regular expressions. -- James GPG Key: 1024D/61326D40 2003-09-02 James McCoy <[email protected]> -- You received this message from the "vim_dev" 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
