From: Dominic Dunlop Date: Thu, 7 Aug 1997 00:00:00 +0000 (+0000) Subject: Document use of - in a regex char class. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84850974f570c6c594cc0df54611ffc5f0b26130;p=p5sagit%2Fp5-mst-13.2.git Document use of - in a regex char class. Subject: [PATCH] Re: regex matcher incorrect At 13:17 +0200 1997-06-24, Ulrich Windl wrote: >In a statement like "$_[0] =~ /^([ugoa]+)([+-=])([rwxst]*)$/;" some >incorrect patterns were matched. As an example "go/rw" was matched. >Adding a backslash in front of the minus, making "[+\-=]", solved the >problem. > >As this is a non-obvious feature, I'd consider that as a bug. Originally >the problem was seen on Linux running the same version of Perl. Thanks Ulrich. You're right. While all UNIX-descended regular expression packages work pretty much the same way in respect how you make "-" a member of a character class, neither the documentation delivered with Perl nor the book "Programming Perl" tells you what to do, and they should. Here's a patch to apply to the perlre.pod documentation file: p5p-msgid: v03102804afd578bcef2c@[194.51.248.88] --- diff --git a/pod/perlre.pod b/pod/perlre.pod index 2b24379..37434a6 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -515,7 +515,11 @@ in C<[]>, which will match any one of the characters in the list. If the first character after the "[" is "^", the class matches any character not in the list. Within a list, the "-" character is used to specify a range, so that C represents all the characters between "a" and "z", -inclusive. +inclusive. If you want "-" itself to be a member of a class, put it +at the start or end of the list, or escape it with a backslash. (The +following all specify the same class of three characters: C<[-az]>, +C<[az-]>, and C<[a\-z]>. All are different from C<[a-z]>, which +specifies a class containing twenty-six characters.) Characters may be specified using a metacharacter syntax much like that used in C: "\n" matches a newline, "\t" a tab, "\r" a carriage return,