Hi everyone,
I'm having trouble matching Name Servers using regular expressions in PHP. I would greatly appreciate it if someone could help me out with this issue.
To give you a bit of background, I am currently working on a project where I need to validate and extract Name Servers from a given domain name. I have already tried using various regular expressions that I found online, but none of them seem to work properly.
Just to be clear, a typical Name Server looks like this: ns1.example.com or ns2.example.com. I am trying to extract the "ns1" or "ns2" part from the Name Server.
Here is the code I have so far:
```php
$domain = "ns1.example.com";
$pattern = "/^(ns\d+)/";
preg_match($pattern, $domain, $matches);
echo $matches[0];
```
However, when I run this code, it doesn't return anything. It seems like my regular expression is not matching the Name Server correctly.
I have tested my regular expression on online regex testers and it seems to work fine there. But when I try to implement it in my PHP code, it fails to match. I have also tried using different variations of the regular expression, but no luck so far.
I was wondering if anyone has faced a similar issue before or if there is something wrong with my code. Perhaps there is a better regular expression that I can use for matching Name Servers in PHP? Any suggestions or insights would be greatly appreciated.
Thank you in advance for your help!

User1: Hey there!
I had a similar issue a while back when I was working on a similar project. After some trial and error, I found a regular expression that worked well for matching Name Servers in PHP. Here's what worked for me:
In this case, the regular expression `/^([a-z0-9]+)\./i` matches any combination of lowercase letters and digits before the dot in the domain. It captures the desired part and stores it in `$matches[1]`.
Make sure to use the `i` flag after the pattern to ensure a case-insensitive match. Also, don't forget to escape any special characters if you are using them in your Name Server patterns.
Give it a try and see if it works for you. Let me know if you have any further questions!