How to find only unquoted array indices in PHP variable and quote them, using Notepad++?


Hi I have several lines of code like these:


and I would like to transform them like this:


On notepad with Find and Replace using regular expression to find them I used this expression:


You know how I could replace the same word by adding: ' ' to the extremes?

>Solution :

You need to look for non quotes in the index notations so replace .*? (which essentially says "anything") with [^']+?. You also can take the PHP definition for a valid variable and us that prior to the index notation to be more exact:


you then replace with:


If you wanted to go a step forward you could use a negative lookahead to exclude integers ((?!\d+)) indices (because those are valid in PHP):


If it is only ever $row you can do:




Leave a ReplyCancel reply