Regular Expressions: RegEx for determining valid PHP class property names?
- by Brian Lacy
I am using PHP's magic __set and __get methods to access a private array in a class. I want to make sure the property names requested (i.e. $myObj->FakeProperty) are valid according to PHP property name rules before accessing them.
My current RegEx isn't doing the trick; with my test values, _12 always falls through the cracks.
I'm not actually sure that my test values even represent a realistic representation of what is and isn't allowed for PHP class property names, but I'm not really too concerned about it, just that I have some sort of rudimentary check in place.
Test Fields:
albert12
12Albert
_12
_Albert12
_12Albert
_____a_1
RegEx:
^(?=_*[A-z]+)[A-z0-9_]+$