我試圖用regular expressions
替換一個字符串,並且這個字符串不包含特定的單詞。正則表達式,如何替換不包含單詞的字符串?
這裏是字符串:
$string = 'mysql_fetch_array($stmt = mysql_query($query));' // Shouldn't match
$string = 'mysql_fetch_array($stmt));' // Should match
正則表達式:
preg_replace('/^(.*)mysql_fetch_(.*)\([ ]?.*(?!mysql_query).*[ ]?\)(.*)$/', $value, $string);
但兩個串匹配上述表達式。
我該如何更換第二個字符串?
所以含有'的mysql_query($查詢)'不應該匹配的字符串? – aelor 2014-09-23 10:52:30