我想給~
更換成|
在folowwing情況下[
]
之間:PHP有條件的字符串替換
{stackoverflow is a [cool~great~fast] website ~ Find your answers [easily~quickly] on stackoverflow}.
注:[
]
之間的文本可以是多。
我試過多個正則表達式但沒有運氣。
我此刻最接近的呼叫:
$text = preg_replace("/\[(.*?)~(.*?)\]/i", "[$1|$2]", $text);
但返回
{stackoverflow is a [cool~great|fast] website ~ Find your answers [easily|quickly] on stackoverflow}.
您應該報告您嘗試過哪些正則表達式。這可能是你犯了一個錯誤,而正則表達式是不正確的。 – kiamlaluno 2010-07-03 22:48:44
括號可以嵌套嗎? – sepp2k 2010-07-03 22:49:36
括號不能嵌套 – brechtvhb 2010-07-03 22:59:17