8

Hi I want to search text inside gvim with the following criteria a&b&(c|d). I know for a&b it is /.*a\&.*b and for c|d it is /c\|d but combining these two doesnt work. what can be the exact command ?

edit: I tried .*a\&.*b\&.*(c\|d), but it is taking it as .*a\&.*b\&.*(c ORed with d) , inc brackets.

edit2: breaking the expression to a&b&c|a&b&d is working,.*a\&.*b\&.*c\|.*a\&.*b\&.*d , but thats not something I am looking for.

mMontu
  • 6,630
  • 21
  • 31
  • Can you provide some examples on what are you trying to do, i.e., a sample text and the expected matches for your (intended) regex? (XY Problem) – mMontu Feb 02 '16 at 12:04
  • @mMontu ok. amm. for example, I want to search lines with following criteria, USB & LENGTH should definitly be there along with either RX or TX. – Krishanu Banerjee Feb 02 '16 at 12:17
  • 4
    () have to be escaped in Vim's regex to be used for grouping, :help /\(. An unescaped ( or ) matches the literal character. – jamessan Feb 02 '16 at 14:51

2 Answers2

8

From :help \&:

2. A branch is one or more concats, separated by "\&".  It matches the last
   concat, but only if all the preceding concats also match at the same
   position.  Examples:
    "foobeep\&..." matches "foo" in "foobeep".
    ".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob"

I want to search lines with following criteria, USB & LENGTH should definitly be there along with either RX or TX.

So it seems impossible that any text would match "USB" AND "LENGTH". You would probably use something like:

\(USB.*LENGTH\).*\(RX\|TX\)

or, using \v to reduce the escaping:

\v(USB.*LENGTH).*(RX|TX)

If you meant USB and LENGTH but in any order:

\v(.*USB&.*LEN).*(RX|TX)
mMontu
  • 6,630
  • 21
  • 31
4

You may want to use :logiPat. It ships with newer versions of Vim.

:LogiPat "a"&"b"&("c"|"d")

For more help see: :h logipat

Peter Rincker
  • 15,854
  • 1
  • 36
  • 45