7

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.

  • 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 2 '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 2 '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 2 '16 at 14:51
6

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)
  • the last one, can you pls rewrite without using \v ? to correlate. – Krishanu Banerjee Feb 2 '16 at 14:11
  • 2
    \(.*USB\&.*LEN\).*\(RX\|TX\) -- you can find the details in :help \v – mMontu Feb 2 '16 at 15:16
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.