What's the simplest way to do this search?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

What's the simplest way to do this search?

Xell Liu
Hi all,

For example, when I want to search all letters and digits (i.e. all
[:alnum:] ) except the two letters "a" and "b" (without quotes), how
should I do that instead of stupidly enumerating all the characters I
want?

The real question I want to ask is:
1. The items I want to include in search are too many to enumerate
them manually, like [\x00-\xff];
2. The items I want to exclude are very few;
What's the simplest way to write the search regular expression?

Thanks very much!

Regards,
Xell

--
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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Christian Brabandt
Hi Xell!

On Do, 05 Aug 2010, Xell Liu wrote:

> Hi all,
>
> For example, when I want to search all letters and digits (i.e. all
> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
> should I do that instead of stupidly enumerating all the characters I
> want?

Something like this should work:
/[[:alnum:]]\&[^ab]


regards,
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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Reid Thompson
In reply to this post by Xell Liu
On Thu, 2010-08-05 at 20:21 +0800, Xell Liu wrote:

> Hi all,
>
> For example, when I want to search all letters and digits (i.e. all
> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
> should I do that instead of stupidly enumerating all the characters I
> want?
>
> The real question I want to ask is:
> 1. The items I want to include in search are too many to enumerate
> them manually, like [\x00-\xff];
> 2. The items I want to exclude are very few;
> What's the simplest way to write the search regular expression?
>
> Thanks very much!
>
> Regards,
> Xell
>

/[^ab]
works for me ( if the above matches A and B, then also do :set noic )

--
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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Stahlman Family
In reply to this post by Xell Liu


Xell Liu wrote:

> Hi all,
>
> For example, when I want to search all letters and digits (i.e. all
> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
> should I do that instead of stupidly enumerating all the characters I
> want?
>
> The real question I want to ask is:
> 1. The items I want to include in search are too many to enumerate
> them manually, like [\x00-\xff];
> 2. The items I want to exclude are very few;
> What's the simplest way to write the search regular expression?

You can use concats.
:help /branch

E.g.,

[[:alnum:]]\&[^ab]

...matches any letter or digit except a or b.

Brett Stahlman

>
> Thanks very much!
>
> Regards,
> Xell
>

--
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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Stahlman Family


Stahlman Family wrote:

>
>
> Xell Liu wrote:
>> Hi all,
>>
>> For example, when I want to search all letters and digits (i.e. all
>> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
>> should I do that instead of stupidly enumerating all the characters I
>> want?
>>
>> The real question I want to ask is:
>> 1. The items I want to include in search are too many to enumerate
>> them manually, like [\x00-\xff];
>> 2. The items I want to exclude are very few;
>> What's the simplest way to write the search regular expression?
>
> You can use concats.

Sorry. The correct term was "branch", not concat...

Brett Stahlman

...[snip]...

--
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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Xell Liu
@Christian
@Brett

Thanks very much for the '\&'. When I read the pattern.txt in vim help
I always ignore the first section and wallow in those "fascinating"
pattern atoms and character classes :-p

@Reid

Thanks all the same.

Regards,
Xell



On Thu, Aug 5, 2010 at 8:41 PM, Stahlman Family
<[hidden email]> wrote:

>
>
> Stahlman Family wrote:
>>
>>
>> Xell Liu wrote:
>>>
>>> Hi all,
>>>
>>> For example, when I want to search all letters and digits (i.e. all
>>> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
>>> should I do that instead of stupidly enumerating all the characters I
>>> want?
>>>
>>> The real question I want to ask is:
>>> 1. The items I want to include in search are too many to enumerate
>>> them manually, like [\x00-\xff];
>>> 2. The items I want to exclude are very few;
>>> What's the simplest way to write the search regular expression?
>>
>> You can use concats.
>
> Sorry. The correct term was "branch", not concat...
>
> Brett Stahlman
>
> ...[snip]...
>
> --
> 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 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
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Nikolay Aleksandrovich Pavlov
In reply to this post by Xell Liu
Ответ на сообщение «What's the simplest way to do this search?»,
присланное в 16:21:09 05 августа 2010, Четверг,
отправитель Xell Liu:

I am surprised that nobody mentioned negative look-behind (/[ab]\@![[:alnum:]]).
Unlike '\&', it is available in all perl-like regex engines (via (?!)), so you
will not restrict your regex experience to vim.

Текст сообщения:

> Hi all,
>
> For example, when I want to search all letters and digits (i.e. all
> [:alnum:] ) except the two letters "a" and "b" (without quotes), how
> should I do that instead of stupidly enumerating all the characters I
> want?
>
> The real question I want to ask is:
> 1. The items I want to include in search are too many to enumerate
> them manually, like [\x00-\xff];
> 2. The items I want to exclude are very few;
> What's the simplest way to write the search regular expression?
>
> Thanks very much!
>
> Regards,
> Xell

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What's the simplest way to do this search?

Xell Liu
On Fri, Aug 6, 2010 at 1:38 AM, ZyX <[hidden email]> wrote:
> I am surprised that nobody mentioned negative look-behind (/[ab]\@![[:alnum:]]).
> Unlike '\&', it is available in all perl-like regex engines (via (?!)), so you
> will not restrict your regex experience to vim.
>
> Текст сообщения:

Thanks very much for telling me that.

I think the reason why nobody mentioned it is that \& is more
intuitive to use (it can be seen as the AND operator).

On the other side, as said by vim help, \@! is a little bit tricky.
It's hard to handle.

However, I found it's very useful in some special cases in the sense
that you can write your regular expression in a *positive* way.

Regards,
Xell

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