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

Re: input foo, output '[F|f][O|o][O|o]'?



On 2013-07-01 at 13:59 -0400, TJ Luoma wrote:
> Before I reinvent the wheel, I thought I'd ask if someone already had 
> (or knew of) a way to take a string of characters and output a 'case 
> insensitive' regex version.
> 
> For example, if I input 'CrashPlan' I'd want to get out 
> [C|c][R|r][A|a][S|s][H|h][P|p][L|l][A|a][N|n]

% foo=CrashPlan
% for c in ${(s::)foo}; do print -n "[${(U)c}|${(L)c}]";done; print
[C|c][R|r][A|a][S|s][H|h][P|p][L|l][A|a][N|n]
%

If this is for use within zsh, then as ZyX suggests it's simpler, even
for regexp cases:

 setopt rematch_pcre
 [[ "cRAShpLAn" =~ (?i)$foo ]]

-Phil



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