Reputation: 2005
I'm trying to catch every hostname that have the exact format:
letters(+or)numbers.example.com
My regex:
$pattern = '/([0-9a-z]*\.)example.net/';
It should work like:
test2155.example.net // Catch
2155.example.net // Catch
Test2155.example.net // Don't Catch
test2155.example.net655 // Don't Catch
[email protected] // Don't Catch
[email protected]@655 // Don't Catch
How i can do it please?
Upvotes: 0
Views: 44
Reputation: 43169
You could use
([a-zA-Z0-9]+)\Q.example.net\E
([a-zA-Z0-9]+) # your original expression
\Q.example.net\E # .example.net literally
Upvotes: 3
Reputation: 92854
Change the quantifier from *
to +
and add word boundary \b
:
/([0-9a-z]+\.)example.net\b
Upvotes: 2