Carl Lowenstein wrote: > On 4/16/07, James G. Sack (jim) <[EMAIL PROTECTED]> wrote: >> Ralph Shumaker wrote: >> > James G. Sack (jim) wrote: >> >> Ralph Shumaker wrote: >> >>.. >> >> In vim, I get the same one-line result with the vim command >> >> >> :/\(ada\|bub\|crc\|dod\).*\(ada\|bub\|crc\|dod\).*\(ada\|bub\|crc\|dod\).*\(ada\|bub\|crc\|dod\) >> >> > >> > *That* gets me what I was expecting (though I don't know why you have a >> > colon in front). I tried it with parentheses but didn't realize I had >> > to escape them (though I now understand the results of that attempt). >> >> The colon is the vim prompt (helps see that I was speaking vimese) >> >> >.. >> > Actually, the ideal (as you correctly concluded) was to search for any >> > lines that contain at least one of each of the four search items, in >> > unknown sequence. (double "yuk!") >> > >> > I've been playing with regex, and it's been a while since I played with >> > grep. So with regex fresh (well, *more* fresh), I naturally thought of >> > it first... >> >> if you stop to think that the 're' in the middle of grep stands for >> Regular Expression, then you should have thought of grep first, eh? >> >> > .. Also, I kinda wanted to be able to see the line in context, >> > which grep precludes. But I found a different way to get what I want >> > with only *one* extra step. :-) >> >> As mentioned, the chained-grep approach may give false matches, >> depending on the actual search data. The painful enumeration of all the >> permutations may be the most reliable as well as the clearest expression >> of the problem logic. >> >> You can always write a script to generate the search pattern. I bet Stu >> could even whip one up as a vim macro. >> >> Probably not as easily done as in emacs (via elisp), I wager. >> > > If you get really serious about this sort of stuff, you ought to look in at > > _The Art of Computer Programming_ Vol 3 Sorting and Searching, Donald > E Knuth, 1997. > Warning -- Sorting occupies 381 pages and Searching 192 pages. > > Side comment: I went to college at the same time and place as Don > Knuth, knew some of the people and places that he discusses in various > reminiscences, but never actually met him.
These questions are neat because they always make one go think a little deeper than the boilerplate recipe level. And along those lines, RS .. .. you do realize, don't you that your test pattern doesn't find your desired matches. That is, it gives false positives, on (say) ada ada ada ada That doesn't seem to be what you wanted, eh? It's because of this that I started yakking about permutations, and then also about chain-greps giving false positives. Regards, ..jim -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
