Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Dec 2014 15:39:55 -1000
From:      parv@pair.com
To:        Robert Bonomi <bonomi@mail.r-bonomi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Perl rename utility assistance
Message-ID:  <20141219013955.GA1591@holstein.holy.cow>
In-Reply-To: <201412171838.sBHIcOht031153@host203.r-bonomi.com>
References:  <54907B51.1060807@gmail.com> <201412171838.sBHIcOht031153@host203.r-bonomi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <201412171838.sBHIcOht031153@host203.r-bonomi.com>,
wrote Robert Bonomi thusly...
>
...
> Your regex "^[:digit:]_" says:
>            "^"             start at the beginning of the name
>             "[:digit:]"    match one character from the following list ':digt'
>                      "_"   match an underscore
>
> For some strange reason, this does not cause a match where there
> are leading digits, .
> to match a single character in the range '0'-'9', the syntax is
> '[[digit:]]'
...

The proper character class to match a digit is "[[:digit:]]",
similar to "[0-9]". Pattern "[:digit:]" is to match numbers in the
locale set, to match any number not just those in range "0-9"
(ASCII).

When run with "warnings" pragma when trying to match /^[:digit:]/,
the problem is shown  ...

  perl -Mwarnings -e 'my $x = q[234y] ; print $x =~ m/^([:digit:])/ '
  POSIX syntax [: :] belongs inside character classes in regex; \
  marked by <-- HERE in m/^([:digit:] <-- HERE )/ at -e line 1.


... (mind that nothing is printed as nothing was matched, but not
due to the warning message itself).


Run the above with "diagnostics" pragma for more information ....

  perl -Mdiagnostics -Mwarnings -e ' ... '


On a side note ...

  perl -Mwarnings -e 'my $x = q[xyz] ; $x =~ s/x(y)/y\1/ ; print $x'
  \1 better written as $1 at -e line 1.
  yyz


-- 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141219013955.GA1591>