Tuesday, October 7, 2014

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

Dear Christian,

as requested I explain my test of the suggested solutions.

I tried three regular expressions and used
:set hlsearch
to see the matched region.

The original full line is
glm::something lmg::else

/\<.\{-}::
as well as
/\<..\{-}::
and
/\<.\{-1,}::
all matched, and highlighted,
glm::something lmg::

The only thing after starting vim -U NONE -u NONE was to
:set nocompatible
and
:set hlsearch

This result could be obtained on vim 7.4 (MacVim) and vim 7.3 (debian wheezy).

Does this answer your question?

Cheers and many thanks!


2014-10-07 13:02 GMT+02:00 Christian Brabandt <cblists@256bit.org>:
> 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.

--
--
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: