Path: csiph.com!pasdenom.info!.POSTED.host-202-22-142-222.static.lagoon.nc!not-for-mail From: Doug713705 Newsgroups: fr.comp.os.unix Subject: Re: Shell : extraire d'une chaine plusieurs sous-chaines Date: Sat, 20 Dec 2025 12:30:32 -0000 (UTC) Organization: redatomik.org Message-ID: References: <10g4rbq$2i1$1@cabale.usenet-fr.net> Reply-To: Doug Le Tough MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 20 Dec 2025 12:30:32 -0000 (UTC) Injection-Info: rasp.pasdenom.info; posting-account="doug.letough@usenet"; posting-host="host-202-22-142-222.static.lagoon.nc:202.22.142.222"; logging-data="26119"; mail-complaints-to="abuse@pasdenom.info" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:fAKQdtc0fa4rL4/axwqZhQ76K9o= sha256:IwvhZkIWBHCT+laFt8U5DjT1kiORi6m5Pyz+fspWmHo= sha1:mSr6kWj3+qCCFnmAYPKIGG4N3Ws= sha256:3ajFLDnL1k5OJA3b688kkJ5XsSP399m7kthVzPk6cew= Xref: csiph.com fr.comp.os.unix:8151 Le 25-11-2025, Olivier Miakinen a écrit : > [diapublication, suivi vers fr.comp.os.unix seul] > > Bonjour, Bonjour, > Je voudrais extraire chaque partie dans une variable différente. > Quelques exemples : > s="test1xyz27" -> v1="test" v2="1" v3="xyz" v4="27" > s="aa9toto000" -> v1="aa" v2="9" v3="toto" v4="000" > s="x012" -> v1="x" v2="0" v3="" v4="12" > En python ça donnerait ça: import re S = ["test1xyz27", "aa9toto000", "x012"] pattern = r'([a-z]+)([0-9])([a-z]*)([0-9]+)' for s in S: v1, v2, v3, v4 = re.match(pattern, s).groups() print(f"v1: {v1}, v2: {v2}, v3: {v3}, v4: {v4}") v1: test, v2: 1, v3: xyz, v4: 27 v1: aa, v2: 9, v3: toto, v4: 000 v1: x, v2: 0, v3: , v4: 12 -- Doug Envoyé depuis mon Jacob Delafon 3000 Turbo