正则表达式的注释
格式:(?# 注释内容)
用途:主要用于复杂的注释
贡献代码:是一个用于连接MYSQL数据库的正则表达式
- $regex = '/
- ^host=(?<!\.)([\d.]+)(?!\.) (?#主机地址)
- \|
- ([\w!@#$%^&*()_+\-]+) (?#用户名)
- \|
- ([\w!@#$%^&*()_+\-]+) (?#密码)
- (?!\|)$/ix';
- $str = 'host=192.168.10.221|root|123456';
- $matches = array();
- if(preg_match($regex, $str, $matches)){
- var_dump($matches);
- }
- echo "\n";
PHP之友评论