Regular expressions and matching

I assume, when you say "$email", that you mean the stuff before the @ sign. In that case you can use this regex:

$email = '[email protected]';
if (preg_match('/^shop.*0@/i', $email) === 1) {
    echo 'Yes!';
}

You can also check using normal procedural code:

$email   = '[email protected]';
$local   = substr($email, 0, strpos($email, '@'));
$amalgam = substr($local, 0, 4) . substr($local, -1);
if (strcasecmp('shop0', $amalgam) === 0) {
    echo "yes";
} else {
    echo "no";
}

Try this regular expression:

/^Shop.*0$/i

This one checks for a Shop at the beginning and a zero at the end.

Tags:

Php

Expression