Guest User

Untitled

a guest
Nov 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Regex for PHP associative array keys that lack quotes
  2.  
  3. ------------------------------------------------------
  4.  
  5. Find with: \$([a-z0-9_]*)\[(?!('|"))([a-z0-9_]*)(?!('|"))\]
  6. Replace with: $\1['\3']
  7.  
  8. \1 and \3 relate to groups in the expression that are whatever what's inside parentheses.
  9.  
  10. The first and third group ([a-z0-9_]*) are equal and each one
  11. matches the variable name and the key name respectively
  12.  
  13. ------------------------------------------------------
  14.  
  15. Matches the following:
  16.  
  17. $your_var_name[your_assoc_key]
  18.  
  19. Which will turn into:
  20.  
  21. $your_var_name['your_assoc_key']
  22.  
  23. ------------------------------------------------------
  24.  
  25. Won't match:
  26.  
  27. $your_var_name["your_assoc_key"] or $your_var_name['your_assoc_key']
Add Comment
Please, Sign In to add comment