To skip the explanation & get to the actual question, jump to below the horizontal line.
PHP variables must start with a $
dollar sign; e.g $my_array
PHP arrays are indexed by scalars (like a C++ STL map or a Python dictionary (and similar to JSON)); e.g $my_array[0]
or $my_array[$my_val]
, or, with strings, $my_array['abc']
(single quote, or $my_array["abc"}
(double quote).
I have some inherited code which does not quote the string index : $my_array[abc]
. That was allowed in previous versions of PHP, but is now causing me problems.
So, I am seeking a reg ex to find an open square bracket [
followed by a character (a .. z, A ... Z
); alternatively, followed by not a digit or dollar sign, whichever is easier.
Astute PHP coders will have seen that I can DEFINE(abc, 'abc')
and use $my_array[abc]
, but that's an outlier & I will handle it manually.