Sunday, August 11, 2013

Re: vim: how to use back reference to compare strings?

Still a one-liner but returns only lines 2+4 for me:

:g/abc\(\d\+).*abc\1\d

But depending on the pattern of your actual use case this may still not
suffice.

Regards,
Niklas


Am Sat, 10 Aug 2013 22:50:27 -0400
schrieb ping song <songpingemail@gmail.com>:

> hi:
> thanks for the response, this look much shorter!
> but this doesn't work either...
>
> :g/\(abc\d\+\).*\1\@!\(.*\)
> 1 abc123 bla bla bla abc123 bla bla
> 2 abc123 bla bla bla abc1234 bla bla
> 3 abc123 bla bla bla abc123 bla bla
> 4 abc123 bla bla bla abc1234 bla bla
> 5 abc123 bla bla bla abc123 bla bla
>
> I'm expecting to see only line 2&4...
>
> any idea?
>
> regards
> ping
>
>
>
> On Sat, Aug 10, 2013 at 5:11 PM, Niklas Reinhart
> <niklas.reinhart@gmail.com>wrote:
>
> > Hi,
> >
> > this works for me:
> >
> > abc\(\d\+\).*abc\1\@!
> >
> > Regards
> >
> > Niklas
> >
> >
> > Am Sat, 10 Aug 2013 16:45:30 -0400
> > schrieb Ping Song <songpingemail@gmail.com>:
> >
> > > thanks. yes I know we can use that way(/1 /2 ..etc).
> > > what I meant is, how to use these to actually do the compare in a
> > > vim ex command line? sth like :
> > >
> > > :g#\(abc\d\+) bla bla \(abc\d\+\)#if /1 != /2 then echo "found a
> > > diff !"
> > >
> > > of course this doesn't work but just some fake code to clarify
> > > what I meant
> > >
> > >
> > >
> > > On Sat, Aug 10, 2013 at 3:30 AM, Marcin Szamotulski
> > > <mszamot@gmail.com> wrote: Hi,
> > >
> > > I am not sure if I understand you correctly but you can use
> > > \(...\) and and then reuse it with \1 (it matches the same string
> > > as what \(...\) have matched).
> > >
> > > Regards,
> > > Marcin
> > >
> > >
> > >
> > > On 00:44 Sat 10 Aug , ping song wrote:
> > > > hi guys:
> > > > I run into a scenario that , I need to compare 2 part of the
> > > > regex string in one line :
> > > >
> > > > "abc123456 bla bla bla abc1234"
> > > >
> > > > so I'm thinking, can we use the backreference, to compare the
> > > > first abc\d\+ with the second one and only print out a message
> > > > in case we detect the different ones ? preferably if this can
> > > > be done with one command...
> > > >
> > > > thanks!
> > > >
> > > > --
> > > > --
> > > > You received this message from the "vim_use" maillist.
> > > > Do not top-post! Type your reply below the text you are
> > > > replying to. For more information, visit
> > > > http://www.vim.org/maillist.php
> > > >
> > > > ---
> > > > You received this message because you are subscribed to the
> > > > Google Groups "vim_use" group. To unsubscribe from this group
> > > > and stop receiving emails from it, send an email to
> > > > vim_use+unsubscribe@googlegroups.com. For more options, visit
> > > > https://groups.google.com/groups/opt_out.
> > > >
> > > >
> > >
> > > --
> > > --
> > > You received this message from the "vim_use" maillist.
> > > Do not top-post! Type your reply below the text you are replying
> > > to. For more information, visit http://www.vim.org/maillist.php
> > >
> > > ---
> > > You received this message because you are subscribed to the Google
> > > Groups "vim_use" group. To unsubscribe from this group and stop
> > > receiving emails from it, send an email to
> > > vim_use+unsubscribe@googlegroups.com. For more options, visit
> > > https://groups.google.com/groups/opt_out.
> > >
> >
> > --
> > --
> > You received this message from the "vim_use" maillist.
> > Do not top-post! Type your reply below the text you are replying to.
> > For more information, visit http://www.vim.org/maillist.php
> >
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "vim_use" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to vim_use+unsubscribe@googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> >
>

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: