regex - Backreference to capturing group in vim -


in text need find string may 1 of followning

foo#foo%foo foo#foo%bar foo#bar%foo foo#bar%bar bar#foo%foo bar#foo%bar bar#bar%foo bar#bar%bar 

i write regex matcher this

/\(foo\|bar\)#\(foo\|bar\)%\(foo\|bar\) 

which works fine.

but want avoid duplication of capturing groups in matcher.

if write

/\(foo\|bar\)#\1%\1 

it matches first , last possible strings mentioned in beginning.

q: reference previous capturing group itself, not previous match?

i under wanting create , reuse sub-patterns , reusing them @amadan , @lcd047 alluded to vim not support behavior aware of.

as alternative can use <c-f> while editing pattern open command-line-window. inside window can edit pattern normal vim commands, e.g. daw, ct), etc. once done can press <cr> , run search/command.

there nice vimcast episode this: refining search patterns command-line window.

for more see:

:h command-line-window :h q/ :h c_ctrl-f 

Comments