PHP正则表达式帮助

时间:2010-01-18 16:21:10

标签: php regex

我似乎无法处理此表达式要提取的内容:

preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match);

$ line 是文本文件中的一行,而 $ match 是一个数组

4 个答案:

答案 0 :(得分:6)

以下是解释:

^               # 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

答案 1 :(得分:2)

可能会尝试捕获这些注释块的行(不包括第一行和最后一行):

/**
 * @param  $arg1 etc...
 * @return bool etc...
 */

答案 2 :(得分:0)

这将匹配表格

的字符串
** *  ***@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"

答案 3 :(得分:0)

@让我觉得该模式试图捕捉电子邮件的元素...... 因为ROT总是记录正则表达式。