对 reg-ex 编译的修改
我有以下正则表达式用于匹配 PHP 类、方法和函数名称来验证它们,它最初取自 PHP 的站点(下面链接)
问题是它不匹配单字符类,例如:
class a{}
class b{}
class A{}
class B{}
正则表达式是:
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
现在我不太擅长正则表达式,因为如果可以的话我选择不使用它们,但这次我选择使用它们。
我需要对正则表达式进行 2 个基本修改:
- 允许单个字符
- 不能以 __ 开头(但可以以单个下划线开头,后跟一个字母)
有正则表达式大师可以帮助我吗?
问候
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的答案:
单字符类:
单下划线类:
双下划线类:
This is the possible answer:
Single char class:
single underscore class:
double underscore class: