Reputation: 667
I am working with php and I am trying to make regex get everything after a certain line (a part of a Dig response).
This is the data I am working with.
; <<>> 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
I just wish to get the two last lines and nothing else (sometimes there are more or less). This almost does what I want, but it only checks for the last : and some responses has a : in the very last line (TXT records).
[^:]+$
Any help is appreciated!
Upvotes: 0
Views: 48
Reputation: 67968
^[^;]*
I guess this simple regex should do it for you.See demo.
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);
Upvotes: 1