单词后的正则表达式文本
Regex text after words
我正在使用 php,我正在尝试让正则表达式在特定行(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 记录)中有一个 :。
[^:]+$
感谢任何帮助!
^[^;]*
我想这个简单的正则表达式应该用于 you.See 演示。
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);
我正在使用 php,我正在尝试让正则表达式在特定行(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 记录)中有一个 :。
[^:]+$
感谢任何帮助!
^[^;]*
我想这个简单的正则表达式应该用于 you.See 演示。
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);