php - 允许在两个双引号正则表达式之间使用连字符
问题描述
我创建了正则表达式来捕捉双引号之间的单词。例子
string = Hi[pause="x-weak"]Parth[pause="weak"]How[pause="medium"]are[pause="strong"]You[pause="x-strong"]tell me
regex = \[\h*pause\h*=\h*"\h*(\w+)\h*"\h*]
它只是匹配[pause="weak"]
。我需要它将所有标签与pause
.
解决方案
你可以使用
\[[^][]*pause="(?P<type>[^"]+)"
这也将赶上type
,请参阅regex101.com 上的演示。
在
PHP
这可能是
<?php
$string = 'Hi[pause="x-weak"]Parth[pause="weak"]How[pause="medium"]are[pause="strong"]You[pause="x-strong"]tell me';
$regex = '~\[[^][]*pause="(?P<type>[^"]+)"~';
if (preg_match_all($regex, $string, $matches)) {
print_r($matches);
}
?>
在 ideone.com 上查看演示。
推荐阅读
- python - 为感知损失计算 VGG 特征的正确方法
- highcharts - 使用悬停工作删除高图中的条形选择
- apache-nifi - 使用 NIFI API 从开放 id 连接提供程序检索访问令牌
- php - PHP CURL 类不接受对象参数
- c# - 通过 C# 向热敏打印机发送信息
- kubernetes - 在 Google Composer/Airflow 上使用 KubernetesPodOperator 挂载文件夹
- json - MariaDB 从数组中提取 JSON 值
- reactjs - 为什么 nextProps 和 this.props 总是相同?
- javascript - 如何在嵌套的 Vue3 编译动态 html 中定义属性?
- html - 标题超过数字位置