Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: case insensitive string match



(Forgot the mailinglist in my first reply, readding)

rahul wrote:
> On Thu, Jan 3, 2013 at 4:31 PM, Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>wrote:
>
>> rahul wrote:
>> > been using this for doing some filtering from an array:
>> >
>> >                 matched=(${(M)array:#*$patt*})
>> >
>> > Now I need to have an option of case insensitive search. Looked through
>> the
>> > user's guide and other sources but I don't see a flag to ignore case. Is
>> > there a way without changing this to use grep.
>>
>> % things=( foo bar bfoor thing other frob )
>> % print -l ${(M)things:#*(#i)foo*}
>> foo
>> bfoor
>>
>> Thanks a lot. I think you meant:
>
>     % print -l ${(M)things:#(#i)*foo*}

Actually, I didn't. The position of the (#i) determines where the
case-insensitivity starts. `*' matches everything anyway, so making it
case-insensitive does not add much.

> When i typed in what you wrote I got a "zsh bad pattern"

Works here, maybe you're missing "setopt extended_glob"?


Regards, Frank



Messages sorted by: Reverse Date, Date, Thread, Author