Reputation: 19057
I'm using vim to do some pattern matching on a text file. I've enabled search highlighting so that I know exactly what is getting matched on each search and am getting confused.
Consider searching for [a-z]*
on the following text:
123456789abcdefghijklmnopqrstuvwxyxz987654321ABCDEFGHIJKLMNOPQRSTUVWQXZ
I expected this search to match zero or more consecutive characters that are in the range [a-z]. Instead, I get a match on the entire line.
Should this be the expected behaviour?
Thanks,
Andrew
Upvotes: 3
Views: 249
Reputation: 799420
You're not getting a match on the entire line, you're getting a match on every character. Your pattern also matches nothing at all, which is matched by every single character.
Upvotes: 2
Reputation: 39943
Empty string matches [a-z]*
... therefore this thing is matching everywhere. Perhaps you want to cut down some of the cases by doing [a-z]+
(1 or more), or [a-z]{4,}
(4 or more).
Upvotes: 2
Reputation: 143314
It's matching the empty strings that occur after every character. It has no way of highlighting empty ranges, so it looks like everything is highlighted.
Try searching for [a-z]\+
instead.
Upvotes: 7