Preg_Match 获取搜索词后的所有行

Preg_Match fetching all lines after a search word

我有以下 html 回复:

   Your Balances: <br><br>Points Balance: 600.03<br>
   <br>Last Transaction(s)
   <br>01/11/2019 100050000000 Location1 .00
   <br>11/28/2018 100053700000 Location2 .50
   <br>10/03/2018 100051800000 Location3 .00
   <br>06/26/2018 100047400000 Location4 .50
   <br>06/04/2018 100046400000 Location5 .00
   <br>

我需要使用 preg_match 来提取 Last Transaction(s) 部分下面的所有文本。我试过的是以下但无法获取所有文本:

preg_match('/Last.*Transaction\(s\)<br>((.)+)/',$input, $output);

但我只收到一行 01/11/2019 100050000000 Location1 .00

任何人都可以协助获取我上面指定的所有文本吗?

您可以像这样使用 \G 标志来做到这一点:

(?:                             # non-capturing group
    \G(?!\A)                    # match after the last match
    |                           # or
    \QLast Transaction(s)\E\s+  # Last Transactions(s) lit. + whitespaces
)
\s*<br>\K                       # whitespaces + <br>, 
                                # "forget what's been matched thus far (\K)"
(?P<value>.+)                   # capture anything in that line

参见 a demo on regex101.com(注意修饰符!)但请注意,解析 HTML(通常是嵌套结构)被认为是一种不好的做法。如果可能,请使用解析器 her。