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">[email protected] or [email protected]

 

which is two emails posted next to each other i just want to get the [email protected])

 

Thanks

Mike

Link to comment
https://forums.phpfreaks.com/topic/200253-regular-expression-help/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.