首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >preg_match_all正则表达式问题

preg_match_all正则表达式问题
EN

Stack Overflow用户
提问于 2013-05-29 03:56:22
回答 3查看 68关注 0票数 0

我正在使用preg_match_all,尝试匹配:

代码语言:javascript
运行
复制
[<? or <?php]
[any amount of space here, at least one, may be newline]
[legendcool]
[any amount of space]
[(] return whatever is in here [)]
[any amount of space]
[?>]

到目前为止,我有这样的想法:

index.php

代码语言:javascript
运行
复制
$the_prophecy = file_get_contents("secret.php");
preg_match_all('~[<?|<?php]\s*[legendcool(](.*?)[)]\s*[?>]~',$the_prophecy,$matches) ;

secret.php

代码语言:javascript
运行
复制
<title>Regex Match all characters between two strings - Stack Overflow</title>
<link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">
<?php          legendcool({'',''})       ?>
<link rel="apple-touch-icon image_src" href="http://cdn.sstatic.net/stackoverflow/img/

例如,在secret.php中,我希望获得{'',''}

你们中有谁知道如何调整我的preg_match_all,使其以我想要的方式工作?

EN

Stack Overflow用户

发布于 2013-05-29 04:00:52

您混淆了方括号和括号,[<?|<?php]应为(<?|<?php)。如果你不想让它捕获任何东西,那就写(?:<?|<?php)

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

https://stackoverflow.com/questions/16800378

复制
相关文章

相似问题

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