Tuesday, October 7, 2014

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

Dear Al,

thank you for your effort and reply.

Unfortunately none of your three suggestions work, even when tested with
vim -U NONE -u NONE.

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?

Cheers!

2014-10-07 12:37 GMT+02:00 A. S. Budden <abudden@gmail.com>:
> Check out \{-} (in ":help \{"). This is an "as few as possible"
> version of *, so you can do:
>
> /.\{-}::
>
> If you want to ensure you match something, you can either do:
>
> /..\{-}::
>
> or
>
> /.\{-1,}::
>
> I tend to use the former as I don't have to think as much...
>
> Al
>
> On 7 October 2014 11:02, Asis Hallab <asis.hallab@gmail.com> wrote:
>> Dear Vim experts,
>>
>> consider the following line
>>
>> glm::something mlg::else
>>
>> The goal is to match the words before and including the double colons. Of course
>>
>> /\([a-zA-Z]\+::\)
>>
>> does the job. But the question arose, if
>>
>> /\<.\+::
>>
>> could be restricted to match
>>
>> glm::something
>>
>> and not
>>
>> glm::something mlg::
>>
>> - So I guess my question is, is there a way to tell vim to please not
>> extend the matched region to be as large as possible, but e.g. take
>> the smallest possible match?
>>
>> Of course I browsed the documentation and asked the most popular
>> search machine. I might have overlooked the answer.
>>
>> Help will be much appreciated.
>> Have a pleasant day and
>> Cheers!
>>
>> --
>> --
>> 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.
>
>
>
> --
> http://www.cgtk.co.uk
>
> --
> --
> 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: