php - 匹配/提取两个字符串之间的所有字符
问题描述
我想从字符串中提取 John Doe\n*DRIVGo*\nVolledige naam: John Doe\nTelefoonnummer: 0612345678\nIP: 94.214.168.86\n
所以我猜正则表达式模式需要提取'Volledige naam:'和'\ n'之间的所有字符。有没有人可以帮助我?
解决方案
您可以使用此正则表达式来捕获组 1 中的名称,
naam:\s+([a-zA-Z ]+)
由于名称只能包含字母和空格,因此使用[a-zA-Z ]+
字符集。
php示例代码,
$str = "\n*DRIVGo*\nVolledige naam: John Doe\nTelefoonnummer: 0612345678\nIP: 94.214.168.86\n";
preg_match('/naam:\s+([a-zA-Z ]+)/', $str, $matches);
print_r($matches[1]);
印刷,
John Doe
推荐阅读
- symfony - 两个不同年份的symfony日期计算不同
- xml - 面包屑网站 Odoo 9 显示错误
- amazon-web-services - 如何为 Amazon ECR 配置自定义域名
- linux - 批量下载文件
- python - 拆分前的数据增强
- android - 无法调试从 Kotlin 中的 Channel 接收到的变量
- sql-server-2008 - SSMS 超时问题
- reactjs - 如何为 windows 平台导出 React 本机代码
- css - IE / ME - 使用 Boostrap 4 将中间按钮文本与 flex 垂直对齐
- angular - Angular - 完全解耦父子模块路由