单词后的Regex文本


Regex text after words

我正在使用php,我正试图让regex在某一行(Dig响应的一部分)之后获取所有内容。

这是我正在处理的数据。

; <<>> DiG 9.8.1-P1 <<>> @ns2.msft.net microsoft.com a +comments +noquestion +noauthority +noadditional +nostats +nocmd
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10742
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; ANSWER SECTION:
microsoft.com.      3600    IN  A   134.170.188.221
microsoft.com.      3600    IN  A   134.170.185.46

我只想得到最后两行,而不是其他的(有时或多或少)。这几乎满足了我的要求,但它只检查最后一行:有些响应在最后一行(TXT记录)中有一个:。

[^:]+$

感谢您的帮助!

^[^;]*

我想这个简单的正则表达式应该可以帮你做到这一点。请参阅演示。

https://www.regex101.com/r/rK5lU1/33

$re = "/^[^;]*/im";
$str = "; <<>> DiG 9.8.1-P1 <<>> @ns2.msft.net microsoft.com a +comments +noquestion +noauthority +noadditional +nostats +nocmd'n; (1 server found)'n;; global options: +cmd'n;; Got answer:'n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10742'n;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0'n;; WARNING: recursion requested but not available'n'n;; ANSWER SECTION:'nmicrosoft.com. 3600 IN A 134.170.188.221'nmicrosoft.com. 3600 IN A 134.170.185.46";
preg_match_all($re, $str, $matches);