首页
学习
活动
专区
圈层
工具
发布

帮助
EN

Stack Overflow用户
提问于 2010-01-18 16:21:10
回答 4查看 179关注 0票数 1

我似乎无法理解这个表达式所要提取的内容:

代码语言:javascript
复制
preg_match("/^(?:[\s\*]*?@([^\*\/]+?)\s(.+))/",$line,$match);

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-01-18 16:24:53

以下是一个解释:

代码语言:javascript
复制
^               # 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

票数 6
EN

Stack Overflow用户

发布于 2010-01-18 16:37:06

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

代码语言:javascript
复制
/**
 * @param  $arg1 etc...
 * @return bool etc...
 */
票数 2
EN

Stack Overflow用户

发布于 2010-01-18 16:27:22

这将匹配窗体的字符串。

代码语言:javascript
复制
** *  ***@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"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2087461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档