1234
1234

Reputation: 579

Need help for Vim Regular Expression

I try to come up a regular expression to capture the following pattern:

I want to include the characters from a-z, but exclude e, f and g I know the characters class in Vim

[^efg]

excludes characters: e, f and g

I have tried follwoing regular expression

%s/[a-z[^efg]]//gc

but it doesn't capture what I want

Upvotes: 1

Views: 75

Answers (2)

Alan Gómez
Alan Gómez

Reputation: 378

Another way to do that:

:%s/[efg]\@!.//g

Because \@! do negative/inverse match.

Upvotes: 0

Rion Williams
Rion Williams

Reputation: 76547

You could consider using the other ranges that you need (i.e. [a-d] and [h-z]) within a single character group, which should match every character except those you explicitly excluded:

[a-dh-z]

Example

enter image description here

You can see an interactive example of this here.

Upvotes: 5

Related Questions