I am facing a challenge with extracting nameserver information from a WHOIS response in a Laravel application. I have tried using regular expressions, but I encountered a compilation error related to PCRE2 not supporting certain escape sequences. Despite multiple attempts to address this issue, I have been unsuccessful in obtaining the desired nameserver information.
Here is a snippet of the WHOIS response I am working with:
"result":"success","status":"unavailable","whois":" ---% This is the IRNIC Whois server v1.6.2.\u003Cbr /\u003E\n% Available on web at http://whois.nic.ir/\u003Cbr /\u003E\n% Find the terms and conditions of use on http://www.nic.ir/\u003Cbr /\u003E\n% \u003Cbr /\u003E\n% This server uses UTF-8 as the encoding for requests and responses.\u003Cbr /\u003E\n\u003Cbr /\u003E\n% NOTE: This output has been filtered.\u003Cbr /\u003E\n\u003Cbr /\u003E\n% Information related to \u0027farsnews.ir\u0027\u003Cbr /\u003E\n\u003Cbr /\u003E\n\u003Cbr /\u003E\ndomain:\t\tfarsnews.ir\u003Cbr /\u003E\nascii:\t\tfarsnews.ir\u003Cbr /\u003E\nnserver:\tns01.farsnews.ir\u003Cbr /\u003E\nnserver:\tns02.farsnews.ir\u003Cbr /\u003E\nnserver:\tns03.farsnews.ir\u003Cbr /\u003E\nnserver:\tns04.farsnews.ir\u003Cbr /\u003E\nsource:\t\tIRNIC # Filtered\u003Cbr /\u003E\n\u003Cbr /\u003E\n\u003Cbr /\u003E\n"
I need to get nameservers from "whois" which are these:
/\u003E\nnserver:\tns01.farsnews.ir\u003Cbr /\u003E\nnserver:\tns02.farsnews.ir\u003Cbr /\u003E\nnserver:\tns03.farsnews.ir\u003Cbr /\u003E\nnserver:\tns04.farsnews.ir\u003Cbr
I have tried using regular expressions like /nserver:\s*(.*?)\u003Cbr/, but it seems there is an issue with PCRE2 support:
// Extract nameservers using regular expressionif (preg_match('/nserver:\s*(.*?)@\\u003Cbr/', $responseData3, $matches)) { // Display the extracted nameserver $nameserver = $matches[1]; dd($nameserver);} else { dd("No nameserver found.");}
And the error is this:
preg_match(): Compilation failed: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u at offset 19
Additionally, I attempted an alternative approach using string functions, but I still couldn't achieve the desired result.
Could anyone please provide insights into a reliable method for extracting nameservers from WHOIS responses in Laravel? Any alternative solutions or suggestions on how to handle the PCRE2 issue would be greatly appreciated.