Closed p5pRT closed 20 years ago
The perlre.pod page doesn't explain a certain behaviour in character classes\, namely that "]" as the first character in a character class is taken as a literal "]"\, not as the terminator of the class.
Perldiag alludes to this\,
unmatched [] in regexp
(F) The brackets around a character class must match. If you wish to include a closing bracket in a character class\, backslash it or put it first. See the perlre manpage.
but I can't find anywhere else in the standard docs that explains this (nor is it in J Friedl's "Mastering Regular Expressions"\, but I guess I'll mail him seperately).
As such\, can I suggest the addtion of a phrase such as
If you want "]" itself to be a member of a class\, put it at the start of the list (after a possible "^") or escape it with a backslash.
to the paragraph about character classes in the perlre.pod file.
I would suggest that the paragraph about character classes (under head2 "Version 8 Regular Expressions")
You can specify a character class\, by enclosing a list of characters in C\<[]>\, which will match any one character from 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\<a-z> represents all characters between "a" and "z"\, 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.)
be changed as follows... (this is line 729 in my distrib)
\<\< in the list. Within a list\, the "-" character is used to specify a
in the list. If you want "]" itself to be a member of a class\, put it at the start of the list (after a possible "^") or escape it with a backslash. Within a list\, the "-" character is used to specify a
Regards
Tim Meadowcroft
_________________________________________________________________________
The information contained in this message is intended for the addressee
only and may contain confidential and/or privileged information.
If you are not the addressee\, please delete this message and notify the
sender; you should not copy or distribute this message or disclose its
contents to anyone.
Any views or opinions expressed in this message are those of the author
and do not necessarily represent those of WestLB or any of its affiliates.
No reliance may be placed on this message without written confirmation
from an authorised representative of its contents.
Migrated from rt.perl.org#1855 (status was 'resolved')
Searchable as RT1855$