Tuesday, October 7, 2014

Re: Regular Expressions: How to restrict match extension to the first occurrence?

Am 2014-10-07 12:50, schrieb Asis Hallab:
(please do not top poste.)

> thank you for your effort and reply.
>
> Unfortunately none of your three suggestions work, even when tested
> with
> vim -U NONE -u NONE.

Please show us exactly what you tried, what you expected and what you
saw.
My guess is, that you used something like /\<.\{-}::
which does what you want, but matches twice, e.g.

mlg::some::else
^^^^^^ the second match here
^^^^^ the first match here


> To clarify, in PERL the regular expression that does what I am looking
> for is achieved by appending ? to the + operator:
>
> perl -e 'my $s = "glm::something mlg::else"; $s =~ /(\S+?::)/; print
> "$1\n";'
>
> So my question can be made clearer
>
> How to achieve the above PERL regular expression matching in Vim?

use the \{-} qualifier as shown. See :h non-greedy


Best,
Christian

--
--
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/d/optout.

No comments: