我想從包含括號的字符串(如{! !}。但是封裝字符串的開頭和結尾不應顯示空格。preg_match_all() - 在括號內使用文本,但不顯示空格
$string = "{! This should be in the output !} this should not be in the output {!show_in_output!} don't show {! show !}";
preg_match_all("/{!(.*)!}/Us", $string , $output);
結果數組是這樣的:
Array
(
[0] => Array
(
[0] => {! This should be in the output !}
[1] => {!show_in_output!}
[2] => {! show !}
)
[1] => Array
(
[0] => This should be in the output
[1] => show_in_output
[2] => show
)
)
但它應該是這樣的:
Array
(
[0] => Array
(
...
)
[1] => Array
(
[0] => This should be in the output
[1] => show_in_output
[2] => show
)
)
有沒有辦法用正則表達式修改來實現這一目標? 謝謝!
爲什麼修改正則表達式時,你可以修剪後正則表達式? –
是的,它可以被修改。 –
當然,你可以修剪後的正則表達式,但我認爲這是不正確的方式來使用正則表達式。 – AndiPower