Monday, January 4, 2010

Re: non-trivial regexp needed, please help

> I am trying to put together a regexp to find pieces of text within one line,
> but I do not know their order.
>
> So far,
> /^.*sample1\|sample2.*sample2\|sample1

Given the lower priority of "\|" in parsing this is

1) any line containing "sample1"
2) or any line containing "sample2" twice
3) or (redundant to #1) any line containing "sample1"

It looks like you want to prioritize your pairings, something like

/^.*\%(\%(sample1.*sample2\)\|\%(sample2.*sample1\)\)

>
> is my best bet but I am still not there.
> Also, best if it would be flexible enough to support arbitrary number of
> samples without much typing.

I don't think there's a natively nice way to do this, but Dr.
Chip has created LogiPat.vim[1] which might simplify some of
these sorts of things. If you have to do this sort of thing
frequently, that would be my first stop.

-tim

[1]
stable at
http://www.vim.org/scripts/script.php?script_id=1290
bleeding edge at
http://mysite.verizon.net/astronaut/vim/ index.html#LOGIPAT

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment