$variable = 'of course it is unnecessary [http://google.com],
but it is simple["very simple"], and this simple question clearly
needs a simple, understandable answer [(where is it?)] in plain English'
每次更改此變量的值。在字符串內搜索
我想要做的是從[...]
獲取文本。所以,如果有[(google)]
,那麼匹配應該是(google)
。
我在尋找一個解決方案,它可以做這些動作:
- 獲得的所有比賽[...],寫入
$all
- 只得到第一比賽,寫入
$first
- 只得到最後比賽,寫入
$last
- 刪除[...]自變量(擦除)的所有比賽
- 僅刪除第一場比賽
- 只刪除最後一場比賽
嘗試不同的正則表達式這一點,像/[\(.*?\)]/
,但結果不是人們所預料的。
試試這個'/ \\ [([^ \\] *)\\] /' – jcubic 2010-09-17 10:37:37
@jcubic,有什麼區別? – James 2010-09-17 10:51:42
括號是特殊的正則表達式字符,如果你想匹配括號,你必須轉義它。 – jcubic 2010-09-17 11:19:32