Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
REGEX将php4样式的数组$test[index]替换为$test[";index";]_Php_Arrays_Regex_Eclipse - Fatal编程技术网

REGEX将php4样式的数组$test[index]替换为$test[";index";]

REGEX将php4样式的数组$test[index]替换为$test[";index";],php,arrays,regex,eclipse,Php,Arrays,Regex,Eclipse,我需要一些关于替换不带双引号的数组索引的帮助 我需要在eclipse中执行此操作,并且当前有以下正则表达式来查找数组,但是,我的替换并没有正确地替换值,而是截断了索引中的文本,从而更改了索引值 例如: echo "This is an example" . $testArray[testIndex]; 当我在eclipse的find字段中输入正则表达式时,以下正则表达式突出显示了[testIndex]: \[[^"$](.*?)[^"$]\] 但是,当我使用下面的正则表达式替换找到的值时,它

我需要一些关于替换不带双引号的数组索引的帮助

我需要在eclipse中执行此操作,并且当前有以下正则表达式来查找数组,但是,我的替换并没有正确地替换值,而是截断了索引中的文本,从而更改了索引值

例如:

echo "This is an example" . $testArray[testIndex];
当我在eclipse的find字段中输入正则表达式时,以下正则表达式突出显示了[testIndex]:

\[[^"$](.*?)[^"$]\]
但是,当我使用下面的正则表达式替换找到的值时,它会截断索引

\["$1"\]
一旦更换,就会发生以下情况

echo "This is an example" . $testArray[testIndex];
变成

echo "This is an example" . $testArray["estInde"];
任何帮助都将不胜感激

干杯

Vish.

试试这个正则表达式:

\["?(.*?)"?\]

在线示例:

将否定字符类放入捕获组。或者,使用lookarounds<代码>\[(?![“$])(.*)(?)谢谢Wiktor Stribiżew,尝试了Oliver的答案,效果很好,而且你的答案对排除的字符也很有效。:)