Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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']
Add Comment
Please, Sign In to add comment