簡體   English   中英

Regexp - php - 檢查是否有對.php文件的引用(但不包括)

[英]Regexp - php - check if there is are references to .php files (but not includes)

我正在編寫一個正則表達式來查找文件是否包含對.php文件的引用,如果是,我想收集文件名。 但是,我必須跳過所有包含和要求。 例如,在以下示例中:

include_once "inc/config.php" ;

include 'inc/php/curl.php' ;

<a href="/index.php">test</a>
if($b == 'test2.php'){
   $c = 4;
}

require_once "inc/php/mail.php" ;    

//$e = $d == 'blabla.php' ? 1 : 2;

比賽應該是:

index.php,test2.php,blabla.php

必須跳過所有包含和要求。 你知道怎么寫這樣的正則表達式嗎?

此正則表達式將僅匹配包含“.php”的行,而不是以include_once include require_once開頭

^(?!include_once)(?!include)(?!require_once).+([\w].php)

這是我將如何做到這一點:

(?<!include\s|include_once\s|require_once\s)["'](?:.*?\/?)(.*\.php)["']

這將只為您提供文件名(根據要求)。

問候。

編輯:

(?:(?:include|require)(?:_once)?\\s+["'](?:.*?\\/?).*\\.php["']|["'](?:.*?\\/?)(.*\\.php)["'])

在沒有負面的lookbehind(因此在JS中工作)並且在引用的名稱之前處理任意數量的空格的情況下將執行該操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM