我需要瀏覽一個巨大的文件並刪除出現在<>
和(. .)
內的所有字符串。PHP正則表達式來修剪文件
這些括號之間,有可以是任何東西:文本,數字,空格等
如: < there will be some random 123 text here >
我可以讀取該文件,並使用str_replace
修剪掉所有的部分,但我不要不知道是如何使用正則表達式來拾取括號內的字符串。
這就是我想做的事:
$line = "this should stay <this should not>";
//$trim = do something here using regex so $trim = "<this should not>"
$line = str_replace($trim,"",$line);
PS: 數據可能跨線傳播:
this should stay
(. this
should
not .)
我不是在正則表達式特別好,但不能簡化你的第一個表達式爲''<.+?> ? – Bojangles
我認爲你必須逃避你的正則表達式中的'('和'.' –
謝謝@SalmanA - 我忘了:) – Benjie