Gentoo Archives: gentoo-user

From: Paul Colquhoun <paulcol@×××××××××××××××××.au>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT scripting - strip zero if between period and digit
Date: Wed, 23 Jan 2019 04:29:28
Message-Id: 8900558.MYR2RyXpKW@bluering
In Reply to: Re: [gentoo-user] OT scripting - strip zero if between period and digit by Adam Carter
1 On Wednesday, 23 January 2019 2:32:43 PM AEDT Adam Carter wrote:
2 > > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \
3 > >
4 > > sed 's/0*\([[:digit:]]\+\)/\1/g'
5 > >
6 > > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3
7 >
8 > Hi David - thanks for that.
9 >
10 > So [[:digit:]] is another way of writing [0-9] and the + just means another
11 > instance of the proceeding expression, right, so your and Francois
12 > solutions are functionally the same, and all the following are the same
13 > too, right?
14 >
15 > [[:digit:]]+
16 > [[:digit:]][[:digit:]]
17 > [0-9]+
18 > [0-9][0-9]
19
20
21 Not quite.
22
23 A trailing '+' means "1 or more of the preceding item", while a trailing '*'
24 means "0 or more".
25
26 [0-9]+ would match any string consisting of only digits, no matter how long,
27 but not an empty string.
28
29
30 --
31 Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/
32 Asking for technical help in newsgroups? Read this first:
33 http://catb.org/~esr/faqs/smart-questions.html#intro