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
Regex for PHP associative array keys that lack quotes | |
------------------------------------------------------ | |
Find with: \$([a-z0-9_]*)\[(?!('|"))([a-z0-9_]*)(?!('|"))\] | |
Replace with: $\1['\3'] | |
\1 and \3 relate to groups in the expression that are whatever what's inside parentheses. | |
The first and third group ([a-z0-9_]*) are equal and each one | |
matches the variable name and the key name respectively | |
------------------------------------------------------ | |
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