Dans des crochets, le trait d'union doit être le premier ou dernier caractère à moins qu'il s'agisse d'un intervalle. Il n'est nul besoin de l'échapper.
[0-9a-fA-F._ -] #Chiffres hexadécimaux, points, underscore, espace, trait d'union
The hyphen character shall be treated as itself if it occurs first (after an initial '^', if any) or last in the list, or as an ending range point in a range expression. As examples, the expressions "[-ac]" and "[ac-]" are equivalent and match any of the characters 'a', 'c', or '-' ; "[^-ac]" and "[^ac-]" are equivalent and match any characters except 'a', 'c', or '-' ; the expression "[%--]" matches any of the characters between '%' and '-' inclusive; the expression "[--@]" matches any of the characters between '-' and '@' inclusive; and the expression "[a--@]" is either invalid or equivalent to '@', because the letter 'a' follows the symbol '-' in the POSIX locale. To use a hyphen as the starting range point, it shall either come first in the bracket expression or be specified as a collating symbol; for example, "[][.-.]-0]", which matches either a right bracket or any character or collating element that collates between hyphen and 0, inclusive.
source : http://pubs.opengroup.org/onlinepubs...bd_chap09.html §1.3.5.7
Partager