Can anyone help me with a regex to check if a string contains more than . (dot) a-z (both cases) 1-9 @ (at) I'm trying to find the special characters etc.
Forgot, I want to pull every email from a database that doesn't contain a .,@,_,-,a-z,1-9 \w+ ,[a-z]+ didn't give me the results I expected..
$con = mysql_connect("localhost","qwerty","qwerty"); mysql_select_db("yourDB", $con); $result = mysql_query("SELECT * FROM users"); while($row = mysql_fetch_array($result)) { if(!preg_match("/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z0-9]{2,4}$/", $row['email'])) { $id=$row['id']; mysql_query("DELETE FROM users WHERE id='$id'"); } } mysql_close($con); PHP:
You don't actually have to pull anything from a MySQL database if all you're going to do is delete what is found. MySQL supports POSIX compliant (extended) regular expressions via REGEXP. You can accomplish the same thing with a query similar to this. DELETE FROM list WHERE email NOT REGEXP '^[a-z0-9_.-]+@[a-z0-9_.-]+\.[a-z0-9]{2,4}$' Code (markup):