Hey Guys, I'm looking to match the following string but having a bunch of problems! String I want to match: test@test.com Code (markup): String I am trying to pull it out of: 003cdiv class=\"data_field\">test@test.com\u003c\/div> Code (markup): Current REGEX I'm using: preg_match_all('/^[^@]*@[@]*\.[^@]*$/', $this->markup, $email); Code (markup): Thanks!
preg_match_all("/[a-zA-Z]+[@]+[a-zA-Z]+.[a-zA-Z]+/i", $string, $matched); PHP: test@test.com Code (markup):
Thanks but I'm looking to match those characters instead of the actual @ sign. Should I just replace the @ sign with those characters?
Try this $data = "003cdiv class=\"data_field\">test@test.com\u003c\/div>"; $pattern = '#([a-z\-\.\_]+)&\#64;([a-z\-\.]+)#si'; if (preg_match($pattern, $data, $m)) { $email = $m[1] . "@" . $m[2]; echo $email; } PHP:
Thanks gvre that seems to have worked! Could you explain the array 1 and 2? Is it storing it in 2 different areas, thats why?
The array is the value returned from the preg_match function. Have a look at when he calls the function he declares $m at the very end, then in turn that allows the programmer to be able to collect those array values. The 1 represents the first condition that matched, the 2 is the second. More info here: http://php.net/manual/en/function.preg-match.php Kind regards, Glen