首页 > 解决方案 > 正则表达式 php 中替代值的 Preg_match 不起作用

问题描述

我需要帮助。我不明白为什么它不起作用。我有以下html。(夫人=夫人,先生=先生)

Herr John Doe <br />
<br />
Frau Jane Smith <br />

我在我的 php 代码中使用 preg_match 遵循正则表达式。

preg_match_all("!<li class='default highlightProfilePremium'>(.*?)<\/li>!is", $result, $match);

for ($i=0;$i<count($match[1]);$i++){
    if(preg_match("!Herr(.*\W)<br \/>|Frau(.*\W)<br \/>!",$match[1][$i], $contact)) {
        $list['contact'][$i] = $contact[1];
    } else {
        $list['contact'][$i] = '';
    };
}

在 regex101 中找到了这两个正则表达式。然而,在 php 中,他只能找到一个。我究竟做错了什么。谢谢你的帮助

标签: phpregexpreg-match

解决方案


推荐阅读