Page 1 of 1

Simple RegEx question [SOLVED]

Posted: Wed Nov 02, 2005 10:18 am
by dyonak
I'm sure this will be pretty easy for someone out there but I can't quite get it. I've got two different ways of accessing the same script to send mail but they format the e-mail slightly different both times. One form formats the email addy properly name@domain.com but the other formats it as name@domain.com@. I want to check the variable in the mail script to see if it has the excess @ at the end and trim it if so. My current regex is written. . .

Code: Select all

if (preg_match ('/[@]{2}/',$email)){
echo 'Multiple @'s';
}
Any ideas?

Posted: Wed Nov 02, 2005 10:20 am
by s.dot

Code: Select all

preg_match('/@$/',$email);
maybe

Posted: Wed Nov 02, 2005 10:22 am
by dyonak
That's it, thanks man!

Posted: Wed Nov 02, 2005 3:31 pm
by Chris Corbyn
Probably not worth firing up the regex engine for that :)

Code: Select all

//    - - -       if last char is "@"        then ret. -1 char      else don't change
$trimmed = substr($string, -1) == '@' ? substr($string, 0, -1) : $string;