这个正则表达式字符串是什么意思?

Kyl*_*yle 1 php regex

我正在尝试调试一些PHP,但我对我的正则表达不是很热,有人可以为我翻译这个吗?(即使它是正则表达式)

public static function fetch($number)
    {
        $number = str_replace(" ", "", $number);
        $html = file_get_contents('http://w2.brreg.no/enhet/sok/detalj.jsp?orgnr=' . $number);
        preg_match_all('/\<td style="width.*\<b\>(.*)[: ]*\<\/b\>/msU', $html, $keys);
        preg_match_all('/\<\/b\>.*\<td.*\>(.*)\<\/td\>/msU', $html, $values);

        if (!$keys[1])
        {
            return null;
        }
Run Code Online (Sandbox Code Playgroud)

保持PHP代码段的上下文,如果它有帮助:D谢谢:)

Xav*_*osa 5

或多或少,它返回{extracted}部分<td style="width ..."><b>{extracted}: </b>


Tim*_*ker 5

我只翻译第一个,第二个是相似的.

/                  # regex delimiter
\<td style="width  # match <td style="width  (unnecessary escaping of < !)
.*                 # match anything (as few characters as possible, see below)
\<b\>              # match <b> (again, unnecessary escaping!)
(.*)               # match anything (lazily) and capture it
[: ]*              # match any number of colons or spaces
\<\/b\>            # match </b>
/msU               # regex delimiter; multiline option (unnecessary), 
                   # dot-all option (dot matches newline) 
                   # and ungreedy option (quantifiers are lazy by default).
Run Code Online (Sandbox Code Playgroud)

编辑:U不是Unicode选项,而是ungreedy选项.我的错.毕竟正则表达并不是那么糟糕:)

我建议使用这些正则表达式:

/<td style="width.*?<b>(.*?)[: ]*<\/b>/s
/<\/b>.*?<td.*?>(.*?)<\/td>/s
Run Code Online (Sandbox Code Playgroud)