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?


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:




Answered By – user3783243

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More