php - php使用字符数从字符串中获取id
问题描述
我有这样的字符串
https://example.com/offers/show?ID=d5589152-1ba7-4bab-b810-1d43e734575e&something=blabla&somethingelse=blabla2
有时字符串看起来不同
https://example.com/o/ABC/PP-Bin/4be93fd6-1380-4403-9945-0c5bc54d05e6?sName=Bam+2rnt
我想按字符数从这个字符串中提取 ID。每个 ID 有 8-4-4-4-12 个字符
解决方案
试试下面的正则表达式:
$subject = "https://example.com/offers/show?ID=d5589152-1ba7-4bab-b810-1d43e734575e&something=blabla&somethingelse=blabla2";
preg_match("/[a-zA-Z0-9]{8}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{12}/", $subject, $matches);
print_R($matches);
推荐阅读
- security - 无法在 AuthenticationFetcher micronaut 中获取客户端证书
- java - Android 如果使用 FTP 协议断开互联网连接,如何从离开的位置自动重试下载
- c# - 使用带有 MSGID 的 ODP.NET 使 Oracle AQ 出队
- amazon-web-services - IAM 角色未能授予 EC2 实例权限
- javascript - 如何在javascript中将对象数组转换为数组数组
- c# - 是否可以为 ToolstripComboBox 菜单项添加快捷键?
- ruby-on-rails - 活动模型序列化程序在部署后突然停止在生产中工作
- javascript - 使用 javascript 简单地隐藏和显示文本
- javascript - 在json中用'-'替换null
- java - 即使项目构建良好,Intellij 也会显示依赖项错误