php - 如何匹配出现在特定子字符串之后的多个子字符串?

标签 php regex preg-match-all

我正在尝试从 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/

相关文章:

PHP正则表达式匹配

javascript - PHP - 无法使用获取的数据

php - 为什么我的查询不起作用?

PHP preg_match_all 失败

安卓工作室 : Regex not working

Java RegEx 全部替换以格式化 XML 中的数据

php - 计算字符串中图像的长度

php - 使用 php 用图片更新现有表单

php - 简单的PHP问题

java - Java中如何检查输入的数字是否有效