INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

regex in query

regex in query

(OP)
I have a table of members for a small website, it was hit pretty hard by spammers recently. I've noticed that many (but not all) of the spammer email addresses have 3 or more groups after the '@' character, like these:
I'm trying to run a query to select these email addresses for further scrutiny. The regex runs correctly when I check it with rubular or regex hero, but when run against the database, it matches all the addresses. Here is the regex:
@([0-9 a-z]+\.){2,}[0-9 a-z]+

and here is the full query:
SELECT * FROM 'members' WHERE 'email' REGEXP '@([0-9 a-z]+\.){2,}[0-9 a-z]+';

MySQL database version 5.1.73 and the server is using utf8 codeset.

Is there an error in my regex or perhaps a database setting that needs to be changed? I have run other queries with simple regex with no problems.

RE: regex in query

Hi

Ask MySQL how is he seeing that regular expression :

CODE --> MySQL

test> SELECT '@([0-9 a-z]+\.){2,}[0-9 a-z]+';
+------------------------------+
| @([0-9 a-z]+.){2,}[0-9 a-z]+ |
+------------------------------+
| @([0-9 a-z]+.){2,}[0-9 a-z]+ |
+------------------------------+
1 row in set (0.00 sec) 
See ? The escaping of the dot vanished as it was treated like a misplaced string escaping. You have to escape the backslash to survive the string parsing and reach the regular expression parsing phase :

CODE --> MySQL

SELECT * FROM 'members' WHERE 'email' REGEXP '@([0-9 a-z]+\\.){2,}[0-9 a-z]+'; 


Feherke.
feherke.ga

RE: regex in query

(OP)
Thank you! worked as expected.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close