PHP正则表达式帮助

PHP正则表达式帮助,php,regex,Php,Regex,我似乎无法理解这个表达式想要提取什么: preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match); $line是文本文件中的一行,而$match是数组 ^ # match the beginning of the input (?: # start non-capture group 1 [\s*]*? # match any character from

我似乎无法理解这个表达式想要提取什么:

preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match);
$line是文本文件中的一行,而$match是数组

^               # 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版本。可以在这里下载:

这里有一个解释:

^               # 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版本。它可以在这里下载:

这将匹配表单的字符串

** *  ***@anything_that_is_not_an_asterisk_nor_a_slash   anything else

$match[1]
在第一个空格前包含
“任何不是星号或斜杠的内容”
$match[2]
包含
“任何其他内容”
这将匹配表单的字符串

** *  ***@anything_that_is_not_an_asterisk_nor_a_slash   anything else

$match[1]
包含
“任何不是星号或斜杠的东西”
在第一个空格之前,
$match[2]
包含
“任何其他东西”
这个@make me think模式试图捕获电子邮件的元素。。。
因为ROT总是记录regex。

这个@make me-think模式试图捕获电子邮件的元素。。。
作为一个ROT,始终记录正则表达式。

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


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



哇,你有自动生成的工具吗?:-)是的,我写了一个PCRE语法,并使用ANTLR创建了一个PCRE解析器/词法分析器,我用它来创建这样一个正则表达式解释。这真是太神奇了!你有这个工具供公众使用吗?还没有。我最近完成了开发,但是适当的文档(和单元测试)正在落后,就像我的宠物项目一样。如果您愿意,我可以在我提供电子邮件时给您发送电子邮件(应该在几周内)。如果是这样的话,请在我的gmail.com上的一次性帐户上给我写一行字。
prometheuzz
Whoa,你有自动生成的工具吗?:-)是的,我写了一个PCRE语法,并使用ANTLR创建了一个PCRE解析器/词法分析器,我用它来创建这样一个正则表达式解释。这真是太神奇了!你有这个工具供公众使用吗?还没有。我最近完成了开发,但是适当的文档(和单元测试)正在落后,就像我的宠物项目一样。如果您愿意,我可以在我提供电子邮件时给您发送电子邮件(应该在几周内)。如果是这样的话,请在我的gmail.com上的一次性帐户上给我写封信,我起初也这么认为,但它与我的帐户非常吻合。请看Kenny和我的答案。我认为意思真的取决于输入/上下文,这些行是什么样子的?起初我也这么认为,但它匹配的更多。参见Kenny和我的答案,我认为其含义实际上取决于输入/上下文,这些行是什么样子的?你知道$line的内容是什么吗?fireeyedboy的文件文本结构正确:/***@class TestClass**@version 1.0*@package TestTool**/你知道$line的内容吗?fireeyedboy的文件文本结构正确:/***@class TestClass**@version 1.0*@package TestTool**/这是一个很好的简单英语解释。我从中获取regexp的代码实际上正是试图提取这种字符串,但由于它在$match[2]中选择了CRLF,所以代码很混乱。这是一个很好的简单英语解释。我从中获取regexp的代码实际上正试图提取这种字符串,但由于它在$match[2]中拾取CRLF,因此非常混乱。这与源文本非常相似。我想知道的是,它试图一步一步地挑选什么,这样我就可以看到它搞乱了什么。这很像源文本。我想知道的是它试图一步一步地挑选什么,这样我就可以看到它在搞什么。