php - 特定字符之前和之后的 PHP 子字符串,直到空格、逗号...?
问题描述
我正在尝试抓取电子邮件。可以说我有一个长字符串:
$str = "this is the email query@stackoverflow.com which you might want to scrape";
$needle_1 = "@";
$needle_2 = array("[ ]","[,]","["]");
我想提取电子邮件。我假设使用 @ 是解决方案。所以基本上,我需要得到@之前和之后的所有字符,直到空格、逗号或“。
目前最好的试验是:
$string = 'this is the email query@stackoverflow.com which you might want to scrape';
$template = "/[\w]+[@][\w]+[.][\w]+/";
preg_match_all($template, $string, $matches);
var_dump($matches);
我怎样才能做到这一点?
解决方案
我觉得它看起来更好
$string = 'this is the email query@stackoverflow.com which you might want to scrap';
$template = "/[\w]+[@][\w]+[.][\w]+/";
preg_match_all($template, $string, $matches);
var_dump($matches);
推荐阅读
- mysql - Mysql Group by 3 个带计数的字段
- solr - 加载类“solr.VelocityResponseWriter”时出错
- mongodb - 一个集合中的两个 ID 字段
- matlab - 更改 Matlab 条形图中条形元素的颜色?
- swift - 带有图像的 UIBarButton 项目覆盖 UINavigationBar 标题
- css - CSS如何在没有负边距的情况下偏移第一个字母?
- python - 熊猫数据框到频率矩阵
- c++ - 使用固定字段宽度最大化 ASCII 中的浮点精度
- amazon-web-services - 基于电子邮件域创建 AWS IAM 用户
- python - 在 Tkinter 中嵌入 matplotlib 图的示例