Jump to content

Regular Expression Help


Hellbringer2572

Recommended Posts

I need some help with regular expression. i am working on a mod to go though posts that are on my site to see if people are posting email address is the post as advertising so i want to search a string for a email address.

 

i have this..

 

$pattern = '/@.*/';

preg_match_all($pattern, $post, $matches);

 

seeing that the @ symbol breaks it up and makes it think it is 3 different words how do i write the regular expression to grab the portion before the @ and the portion behind the @ and stop at the end of the .com

 

(when i ran that code i get this.....

 

[0] => @HOTMAIL.COM">testemail@HOTMAIL.COM or testemail2@HOTMAIL.COM

 

which is two emails posted next to each other i just want to get the testemail@hotmail.com)

 

Thanks

Mike

Link to comment
Share on other sites

Your expression isn't specific enough. Quite often people put something like "@someuser ..." to address someone specifically, but your expression would match this too. You'll easily be able to find a decent regexp to match email addresses on the internet, and you can just modify that to also 'backreference'  the parts of the string you need.

 

http://www.regular-expressions.info/brackets.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.