From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 3A5FE257A8 for ; Fri, 15 Nov 2024 06:49:52 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1731649792; b=dmyDqxXgydKe7v9bSojo/nM/in0V0uoh6LbiNY+lQK3rpOu5Z4sMexklgXKL6l0LNSjsKXGitL H4BKreXf+CT9UGTjcgsgSnXrHKOQNeDksMx+ortLf8vDPZypvScpi5Wf5znHw25PIetV0x7PyT 4aqagY+d49nriOieVodVkb6KDlSRq72+mcByhEpftvptturJdw1iIhqwI2NEt98Bgc+sSMY4m3 JSCRqKGmT6GfPi4eC9bVeU9Td6VNUZAks+F6XUupLphDN2UqcKbzAIdozqSICItTFisK6eqS1s hVuphaubfEnPOOjo63l9eOo/0CagXNpjeuyOZ11CGtGGSQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f176.google.com) smtp.remote-ip=209.85.208.176; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1731649792; bh=zdUfyd7Fqe+NFFopxSJzazb5/fYqnP5vGhBVpKi68DU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=YbUR+hD2+pGIomz6oY+migCRtUy1YLcNVbnckA17lvIQ3k4ct9jlN864F3vPw7/ONPVy7VoAKZ Snlv3GM4qVNVWjl5lFqI9J03T8bVQ9Ko58Z2xKfsMvNPrbx5x2yDbFs5r+nOx+94mj+Jl29Z+y 1AyDh1dMO/3esCAcUVQAtvUhhZqP4RPLU4BsOSuvetpTNWZdnMf2joJu/rZfRJJC5Q+tIrcgZ5 ooogM8/OeetJ+JUC3vjMRI0irCIfzP5Y4Mssv/mf2qN0Gu0OkiMq22XWsySzHUdnO0YJrkixQb W1Xr9hqyRGIhL0EWyY5FqsHTFH19eC907uuBVjUzMolJ0g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=sr1Cwgatkz9g9mEpMQV9UXzD25De5nAcPHvzW/hjbRg=; b=dYr/cHOrKoaTevugOEHNERpyOb Ci00QhfG6oEWkwXevCJErfbILvsM41nJIUHAgOdCiUnU6RUN+oQQaj6lqEs6iDpROFWN2oUp8udta Kl7snFp4QOtFhGCEwOko7y0zanJW1ZDOcdKW50XtmnJBH7jAYuv/Q9p+lQimtzmwn6+AUgGs8iX5m 7Nmd7xKFigx36C7VmjAwSuAvXDqjokcNfFG4qb90KwW26D/BsH5I2PassgQHyKiTXWzx6dz1G6jQu YW3ki3+qOC8u2IQNWVblkhzfL44Do/BTew+6YxbsvyQZ+XPeyuE/uhf1XmdXQr3817PUwrMexVCki JOSLQdIw==; Received: by zero.zsh.org with local id 1tBpDL-000JOI-Ma; Fri, 15 Nov 2024 05:49:51 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f176.google.com) smtp.remote-ip=209.85.208.176; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f176.google.com ([209.85.208.176]:60614) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1tBpCa-000Iiu-9i; Fri, 15 Nov 2024 05:49:04 +0000 Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2ff3232ee75so15260721fa.0 for ; Thu, 14 Nov 2024 21:49:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731649743; x=1732254543; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sr1Cwgatkz9g9mEpMQV9UXzD25De5nAcPHvzW/hjbRg=; b=P1NGJAIOSv8bf4BpupLq21IdU1CODFsTnjXR1Db/kCEAautuCmdicm7Co3ElmExucR 8V7x9Ss+el9/gMnSlfxmQAdQAeB+SH3QzcydgVZzUT/8h8+qSHFkNKNZATR/yWMbUxtg 3aKY887K6Shka718blQL4ucAFOvn0G+u9oOGRpREkJpLwTNA9oZbaV99nshHz3JU+ZHc uhTt32wDs0nikOb4oPkx028ZfUovFFJQynKx/HeeIVZEJbA7g8mr+mgTn1LjuYPViZGM 10Cu/YZzeYFeNz3fNfmjBFOhvK2lFICkk9sJzQw2JU92qJ6vqYj1XULBQX3h0mF8qdDG 8cTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731649743; x=1732254543; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sr1Cwgatkz9g9mEpMQV9UXzD25De5nAcPHvzW/hjbRg=; b=DMWCn+sHgZJqzUGKwjFzQBSyZ2Yq4oiz9LT0t6PmYmibU3LDZIrTvaSN54xzNgg7zg PDHX9R5dHpI/T/cx1ct5HSftUkSbheZxlSfSG+6k6BCiU5sQUW+dJz3bPJUAhNXbMA5o Scvstpu3Cld6zK7EQoqhwtDQijYbWaavyvw4DjEkYGLPEfPLFiWutTeRuBKkD6Jbeum9 FTUtaMyaFijA1PRqP7Gm+Of8icQy3Gsxa64eVqa1+Znb9asWAgauO32OpFkiQhNNekH2 e4HhCPHVgao/KHD1JRJ0en8s+PL2CXQ0ym5wyBDt+jpjK99CGpOk5/g+MvGsAUuvvgDZ koNg== X-Gm-Message-State: AOJu0Ywzo/G2wHwJ5ihK/NJa9tnxAXTybSdtPOST4opnJyZnnR/ILsaZ nCl72J0+TSqI6ETWwMr6bValfBZ1T00VUIuje1l1Bfey6yRzZstH5WjrJg/Ovv2DYfTsJBmxrH9 HXL98poOvRKgYwBZVtGOPQ6aopTg= X-Google-Smtp-Source: AGHT+IG6OL9fZOwwCFgXLOLIcyrspK6rxTP5OoWaKzkz+7A7m6bVarF6btx9hgy+/HIm2rIvOjvwuhQWvxqn5bnskFY= X-Received: by 2002:a2e:a912:0:b0:2fb:57d6:f464 with SMTP id 38308e7fff4ca-2ff6095e992mr6341421fa.20.1731649743210; Thu, 14 Nov 2024 21:49:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Fri, 15 Nov 2024 06:48:49 +0100 Message-ID: Subject: Re: Testing whether a string matches any pattern from a list To: Philippe Altherr Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 30108 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Fri, Nov 15, 2024 at 1:13=E2=80=AFAM Philippe Altherr wrote: > > I have an array that contains a list of patterns and a string. I > would like to check whether the string matches any of the patterns > in the array. For example if patterns=3D("foo*" "*bar"), then a test > for "foob", "obar", and "foobar" should return true and one for > "ooba" should return false. You can join the elements of the array with "|" as the separator, and then match against it: [[ $string =3D=3D (${~${(j:|:)patterns}}) ]] You could also restructure your code to have a single pattern to begin with= : pattern=3D'(foo*|*bar)' [[ $string =3D=3D $~pattern ]] Roman