I have such text:
<Neednt@email.com> If you do so, please include this problem report. <Anotherneednt@email.com> You can delete your
own text from the attached returned message.
The mail system <Some@Mail.net>: connect to *.net[82.*.86.*]: Connection timed out
I have to parse email from it. Could you help me with this job?
upd
There could be another email addresses in <%here%>. There should be connection between 'The mail system' text. I need in email which goes after that text.
Considering this text is stored in $text, what about this :
$matches = array();
if (preg_match('/<([^>]+)>/', $text, $matches)) {
var_dump($matches[1]);
}
Which gives me :
string 'Some@Mail.net' (length=13)
Basically, I used a pretty simple regex, that matches :
<
character>
character : [^>]
[^>]+
([^>]+)
>
characterSo, it captures anything that's between <
and >
.
Edit after comments+edit of the OP :
If you only want the e-mail address that's after The mail system, you could use this :
$matches = array();
if (preg_match('/The mail system\s*<([^>]+)>/', $text, $matches)) {
var_dump($matches[1]);
}
In addition to what I posted before, this expects :
The mail system
\s*
You want to use preg_match()
and looking at this input it should be simple:
<?php
if (preg_match('/<([^>]*?@[^>]*>/', $data, $matches)) {
var_dump($matches); // specifically look at $matches[1]
}
There are other patterns that would match it, you don't have to stick to that same pattern. The '<' and '>' in your input are helpful here.