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

case-insensitivity of =~ operator



Hey,

today I stumbled across this paragraph in zsh's info documentation
again. Citing »Description of Options«:

> CASE_MATCH <D>
>      Make regular expressions using the zsh/regex module (including
>      matches with =~) sensitive to case.

It does not apply to =~ if the zsh/pcre module is loaded. Test script:

----------------------------------------
#!/bin/zsh

export LC_ALL=C

zmodload zsh/pcre
setopt no_case_match

line=Hello
if [[ $line =~ He ]] print match case 1
if [[ $line =~ he ]] print match case 2
if [[ $line -pcre-match He ]] print match case 3
if [[ $line -pcre-match he ]] print match case 4

pcre_compile He
pcre_match $line && print match case 5

pcre_compile -i He
pcre_match $line && print match case 6
----------------------------------------

Output:

----------------------------------------
match case 1
match case 3
match case 5
match case 6
----------------------------------------

Yes, the paragraph above states zsh/regex and not zsh/pcre, but as
zsh/pcre's presence can be… well… it's hard(er) for scripts do detect.

What I'm asking for are two things:

1. Make the paragraph above a bit clearer. An example what would work
   for me:

   > Make regular expressions using the zsh/regex module (including
   > matches with =~ if the zsh/pcre module is not loaded) sensitive to
   > case.

2. Provide an option for making matches with zsh/pcre including
   pcre_match and =~ case-insensitive.

Alternatively extend CASE_MATCH to work on the =~ provided by zsh/pcre,
too and update the info section accordingly. This might make more sense
considering that pcre_match must be used with pcre_compile in tandem and
pcre_compile provides -i already.

Thanks for your consideration.

Kind regards,
mosu

Attachment: pgpVtY5OkeS_q.pgp
Description: PGP signature



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