Forum Moderators: coopster

Message Too Old, No Replies

RegEx for an email address

Need email from the middle of a string

         

trillianjedi

10:15 pm on Aug 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need some help from the RegEx pro's ;)

I have a string which contains all manner of junk, but an email address in the middle, something like:-

$txt='100 10 "u" "EM" "!^.*$!email:dean@example.com!"';

If it looks familiar it's a DNS NAPTR record. I need to extract the email part.

The email address will always start "!email:"

and will always end with a "!"

Is there a simple RegEx/preg I could use to extract that email addy (in this example case I'd be after "dean@example.com") to a new string?

eeek

11:36 pm on Aug 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just take the start and end strings (escaping any characters that need it) and put a .* between them.

dreamcatcher

7:15 am on Aug 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I can tell you how to do it without regex. ;)

$string = '$txt=\'100 10 "u" "EM" "!^.*$!email:dean@example.com!"';

echo str_replace('!"','',substr($string,strpos($string,'email:')+6,strlen($string)));

dc