PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
//sample text
$str = "For general inquiries contact info@sololearn.com. For partnerships and other offers contact contact@example.com.";
// regex for email matching
$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
// preg_match_all returns an associative array
preg_match_all($pattern, $str, $matches);
//print the matches
foreach ($matches[0] as $val) {
echo $val . '<br />';
}
?>
Enter to Rename, Shift+Enter to Preview
OUTPUT
Запуск