我似乎无法理解这个表达式所要提取的内容:
preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match);$line是文本文件中的一行,而$match是数组。
发布于 2010-01-18 16:24:53
以下是一个解释:
^ # match the beginning of the input
(?: # start non-capture group 1
[\s*]*? # match any character from the set {'0x09'..'0x0D', '0x20', '*'} and repeat it zero or more times, reluctantly
@ # match the character '@'
( # start capture group 1
[^*/]+? # match any character from the set {'0x00'..')', '+'..'.', '0'..'ÿ'} and repeat it one or more times, reluctantly
) # end capture group 1
\s # match a whitespace character: [ \t\n\x0B\f\r]
( # start capture group 2
.+ # match any character except line breaks and repeat it one or more times
) # end capture group 2
) # end capture group 1正则表达式将匹配的示例字符串如下:* * *@abc asd
编辑:
我已经发布了一个解析器的beta版本,用于生成上面的解释。它可以在这里下载:http://big-o.nl/apps/pcreparser/pcre/PCREParser.html
发布于 2010-01-18 16:37:06
可能会尝试捕获这样的注释块行(不包括第一行和最后一行):
/**
* @param $arg1 etc...
* @return bool etc...
*/发布于 2010-01-18 16:27:22
这将匹配窗体的字符串。
** * ***@anything_that_is_not_an_asterisk_nor_a_slash anything else$match[1]在第一个空格之前包含"anything_that_is_not_an_asterisk_nor_a_slash",$match[2]包含" anything else"。
https://stackoverflow.com/questions/2087461
复制相似问题