[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#19953: egrep: 'Invalid range end' - bug or not?
From: |
Eric Blake |
Subject: |
bug#19953: egrep: 'Invalid range end' - bug or not? |
Date: |
Thu, 26 Feb 2015 08:06:02 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
On 02/26/2015 06:28 AM, George Shuklin wrote:
> $ echo 'sample-text'|egrep '[0-9\-a-z]'
> grep: Invalid range end
There are different regex flavors. Some, like perl, allow you to write
[...\-...] to include a literal '-' in the middle of a larger set of
characters. But others, like the POSIX BRE (basic) and ERE (extended)
flavors do not. In these flavors, the ONLY way to include literal '-'
in a character set is to put it at the front or at the back of the set
being enumerated. Any appearance of '\' in the set is taken literally;
there is no way to use '\' as an escape character.
Thus, your attempt here is requesting the set consisting of the range
from '0' to '9', from '\' to 'a', and then an unexpected '-' character
that is not the end. It is invalid per POSIX.
>
> but:
>
> $ echo 'sample-text'|egrep '[0-9a-z\-]'
This requests the set from '0' to '0', the set from 'a' to 'z', the
literal '\', and the literal '-'.
As Bernhard pointed out, this is not a coreutils bug. But it is also
not a grep bug. It is your usage that is at fault.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature