GNU bug report logs -
#15410
[:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]
Previous Next
Reported by: Nick Aganan <thesysad <at> gmail.com>
Date: Wed, 18 Sep 2013 16:13:02 UTC
Severity: normal
Tags: notabug
Done: Eric Blake <eblake <at> redhat.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#15410: [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]
which was filed against the grep package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 15410 <at> debbugs.gnu.org.
--
15410: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15410
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
tag 15410 notabug
thanks
On 09/18/2013 10:07 AM, Nick Aganan wrote:
> [:alnum:] is defined as
>
> Alphanumeric characters: ‘[:alpha:]’ *and* ‘[:digit:]’; in the ‘C’ locale
> and ASCII character encoding, this is the same as ‘[0-9A-Za-z]’.
This sense of "and" correctly means the combination, where characters
from either class satisfy the regex. Writing '[[:alnum:]]' is the same
as writing '[[:alpha:][:digit:]]'
> Example:
>
> # cat /tmp/c
>
> adc
>
> x1y1z123
>
> 456
[Your mailer is rather unconventional, and sticks lots of useless
whitespace into your content]
>
>
>
> # grep [[:alpha:]] /tmp/c
>
> adc
>
> x1y1z123
Whoops - you didn't quote your shell argument. I suspect you have some
single-character file names in your current directory (further bolstered
by the fact that you named your file /tmp/c, although it is not obvious
whether your current working directory is /tmp or elsewhere).
Therefore, you are falling victim to shell globbing.
Remember, if a file named 'a' exists in the current directory, then
unquoted [] expressions perform globs that might be replaced by that
file name:
$ touch a
$ echo '[[:alpha:]]' [[:alpha:]]
[[:alpha:]] a
You are NOT grepping for the char class "[[:alpha:]]", but for the
entirely different regex that matches the unfortunate file name
expansion of your glob. Use shell quotes properly, and you will then
see the desired answers. Or prepend 'echo' to your grep command to see
what arguments were actually being handed to grep.
Given that the problem is in your lack of shell quoting, and not in
grep, I'm closing this as not a bug. However, feel free to respond if
you have more comments.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
[Message part 5 (message/rfc822, inline)]
[Message part 6 (text/plain, inline)]
[:alnum:] is defined as
Alphanumeric characters: ‘[:alpha:]’ *and* ‘[:digit:]’; in the ‘C’ locale
and ASCII character encoding, this is the same as ‘[0-9A-Za-z]’.
AND = need to satisfy *BOTH* alpha and digit
OR = need to satisfy *EITHER* alpha or digit
It looks like ‘[:alpha:]’ *AND* ‘[:digit:]’ functions as ‘[:alpha:]’ *OR* ‘
[:digit:]’, See example
Example:
# cat /tmp/c
adc
x1y1z123
456
# grep [[:alpha:]] /tmp/c
adc
x1y1z123
# grep [[:digit:]] /tmp/c
x1y1z123
456
# grep [[:alnum:]] /tmp/c
adc
x1y1z123
456
### if [:alnum] functions as ‘[:alpha:]’ *AND* ‘[:digit:]’, it should show
x1y1z123 only
[Message part 7 (text/html, inline)]
This bug report was last modified 11 years and 304 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.