I have the following Regex used to match PHP Class, method and Function names to validate them, it was originally taken from PHP’s site (Linked Below)
The problem is that it does not match single character classes, for example:
class a{}
class b{}
class A{}
class B{}
The regex is:
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
Now im not super at Regular Expressions as I choose not to use them if I can help it, but on this occasion I chose to use them.
I need to make 2 basic modifications to the regex:
- Allow single character’s
- Cannot start with __ (But can start with a single underscore followed by a letter)
are there any Regular Expression guru’s who can help me.
Regards
This is the possible answer:
Single char class:
single underscore class:
double underscore class: