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

Re: [[ 'abcde' =~ (#i)Bcd ]]



On Mon, Nov 7, 2022, at 4:26 PM, Roman Perepelitsa wrote:
> (#i) only works with pattern matching. For regex the easiest
> workaround is to convert left-hand-side to lowercase:
>
>     foo=XaBcX
>     [[ ${(L)foo} =~ abc ]] && echo match
>
> Another option is to use zsh/pcre module. See
> https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fpcre-Module.

If you're not using zsh/pcre, yet another option is to disable
CASE_MATCH.  It's a bit drastic, though.

You may also be able to use some nonstandard extensions defined by
your host system's regex library, but that would make your script
highly dependent on said library.

> I find it extremely rare in practice that I need a regex match in zsh.

I concur with Roman.  I doubt you actually need case-insensitive
regex.

-- 
vq




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