Created
July 5, 2012 09:52
-
-
Save nelsonr/3052693 to your computer and use it in GitHub Desktop.
Regex for PHP associative array keys that lack quotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Note! - This gist uses Komodo specific regex shortcuts | |
| ------------------------------------------------------ | |
| Find with: \$(.*)\[(?!('|"))(.*)(?!('|"))\] | |
| Replace with: $\1['\3'] | |
| ------------------------------------------------------ | |
| Matches the following: | |
| $your_var_name[your_assoc_key] | |
| Which will turn into: | |
| $your_var_name['your_assoc_key'] | |
| ------------------------------------------------------ | |
| Won't match: | |
| $your_var_name["your_assoc_key"] or $your_var_name['your_assoc_key'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment