我正在尝试从 nginx 配置文件中读出服务器名称。
我需要在这样的行上使用正则表达式:
服务器名称 this.com www.this.com someother-example.com;
我正在使用 PHP 的 preg_match_all()
并且到目前为止我已经尝试了不同的方法:
/^(?:server_name[\s]*)(?:(.*)(?:\s*))*;$/m
// no output
/^(?:server_name[\s]*)((?:(?:.*)(?:\s*))*);$/m
// this.com www.this.com someother-example.com
但我找不到合适的域来将域列为单独的值。
[
0 => 'this.com',
1 => 'www.this.com',
2 => 'someother-example.com'
]
最佳答案
正如鲍勃的叔叔所写:
(?:服务器名称|\G(?!^))\s*\K[^;|\s]+
成功了!
关于php - 如何匹配出现在特定子字符串之后的多个子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29080061/