求解一行代码的意思
我的读一个程序的时候,看到一行代码是这样的
if (/^ +([0-9.-]+) +([0-9.-]+) +([0-9.-]+)/)
请问([0-9.-]中的第二个减号-代表什么意思?
if (/^ +([0-9.-]+) +([0-9.-]+) +([0-9.-]+)/)
请问([0-9.-]中的第二个减号-代表什么意思?
作者: helitrope 发布时间: 2011-05-15
回复 helitrope
[0-9.-]中的第二个-应该就是它本身
[0-9.-]中的第二个-应该就是它本身
作者: yinyuemi 发布时间: 2011-05-15
回复 yinyuemi
恩,呵呵,谢谢您啊!
恩,呵呵,谢谢您啊!
作者: helitrope 发布时间: 2011-05-15
这个在 perlre 中有讲
QUOTE:
You can specify a character class, by enclosing a list of characters in [] , which will match any 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 specifies a range, so that a-z represents all characters between "a" and "z", inclusive. If you want either "-" or "]" itself to be a member of a class, put it at the start of the list (possibly after a "^"), or escape it with a backslash. "-" is also taken literally when it is at the end of the list, just before the closing "]". (The following all specify the same class of three characters: [-az] , [az-] , and [a\-z] . All are different from [a-z] , which specifies a class containing twenty-six characters, even on EBCDIC-based character sets.) Also, if you try to use the character classes \w , \W , \s, \S , \d , or \D as endpoints of a range, the "-" is understood literally.
作者: zhlong8 发布时间: 2011-05-15