[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: case $var in $list) issue
From: |
Zachary Santer |
Subject: |
Re: case $var in $list) issue |
Date: |
Fri, 1 Nov 2024 13:55:28 -0400 |
On Fri, Nov 1, 2024 at 1:27 PM #!microsuxx <fxmbsw7@gmail.com> wrote:
>
> On Fri, Nov 1, 2024, 18:19 Zachary Santer <zsanter@gmail.com> wrote:
>>
>> On Fri, Nov 1, 2024 at 12:56 PM #!microsuxx <fxmbsw7@gmail.com> wrote:
>> >
>> > On Fri, Nov 1, 2024, 17:24 Zachary Santer <zsanter@gmail.com> wrote:
>> >>
>> >> IFS='|'
>> >> if [[ one =~ ${array[*]} ]]; then
>> >> printf 'ye\n'
>> >> fi
>> >
>> >
>> > but enables free regex parsing in arr
>> >
>> > a bit further for complicated strings :
>> > but still needs regex escaping
>> > maybe replace every char to be inside a [<here>] char class
>> >
>> > arr=( a b c ) IFS=\|
>> > arr=( "${arr[@]/#/^}" ) IFS=$' \t\n'
>> > [[ one =~ ${arr[*]/%/$} ]]
>> >
>> > plus , regex escape
>>
>> Ah, yes.
>>
>> IFS='|'
>> if [[ one =~ ${array[*]//[][}{)(.*?+|'"\]/\\&} ]]; then
>> printf 'ye\n'
>> fi
>
>
> i dunno this style
> (.*? means first match only , like non greedy .* ?
> since when does this work in bash
> i remember from perl at around year 2003
I didn't test this at all, but
> [][}{)(.*?+|'"\]
is all one big [...] expression, so
> ${array[*]//[][}{)(.*?+|'"\]/\\&}
would ensure that there's a backslash in front of every one of the
characters within that, instead of putting a backslash in front of
every character, period. I guess that wouldn't be the end of the
world:
> ${array[*]//?/\\&}
Though this wouldn't work out how I might like when \n, \t, etc have
special meaning, i.e. in a sed expression.
Still more straightforward than doing this:
> shopt -s patsub_replacement
> echo ${arr[*]//?/[&]}
- Re: case $var in $list) issue, (continued)
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, Greg Wooledge, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, Greg Wooledge, 2024/11/01
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, Greg Wooledge, 2024/11/01
- Re: case $var in $list) issue, Chet Ramey, 2024/11/02
- Re: case $var in $list) issue,
Zachary Santer <=
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01