On Wednesday, 23 January 2019 2:32:43 PM AEDT Adam Carter wrote:
> > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \
> > 
> >     sed 's/0*\([[:digit:]]\+\)/\1/g'
> > 
> > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3
> 
> Hi David - thanks for that.
> 
> So [[:digit:]] is another way of writing [0-9] and the + just means another
> instance of the proceeding expression, right, so your and Francois
> solutions are functionally the same, and all the following are the same
> too, right?
> 
> [[:digit:]]+
> [[:digit:]][[:digit:]]
> [0-9]+
> [0-9][0-9]


Not quite.

A trailing '+' means "1 or more of the preceding item", while a trailing '*' 
means "0 or more".

[0-9]+   would match any string consisting of only digits, no matter how long, 
but not an empty string.


-- 
Reverend Paul Colquhoun, ULC.     http://andor.dropbear.id.au/
  Asking for technical help in newsgroups?  Read this first:
     http://catb.org/~esr/faqs/smart-questions.html#intro




Reply via email to