Vim regex to search for lines containing string1 AND string2

regular expressionvim

How in vim/vi can I search for all lines that contain string1 and string2, where either string can appear anywhere on the line separated by whitespace and possibly other words?

I would also like to know how to do this using the less pager search (/).

Best Answer

Find two words in either order in a line:

/.*red\&.*blue

or

/\(red.*blue\)\|\(blue.*red\)

Other tools use a slightly different regular expression dialect; in less, you'd use:

/(red.*blue|blue.*red)
Related Question