Simple regular expression for a spam filter

Posted on 2011-05-10
Last Modified: 2012-05-11
I need a regular expression for a spam filter. Basically, I’m receiving particularly annoying spam from varying address, but with pretty characteristic title content, and I could reject emails based on this title pattern.

The titles are in the form of:


so it should pretty easy to crate a RegEx for them, but I have no experience in this area.

So, the RegEx should mach the following criteria:

-The string contains at least 50 characters (letters, digits, signs)
-The string does not contain space

Question by:npaun
    LVL 11

    Expert Comment

    Try this:
    if( preg_match('/^[^ ]{50,}$/i',$title) == 1 )
         // do something

    Open in new window

    LVL 3

    Accepted Solution

    try .[^ ]{50,}

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now