user1410812
user1410812

Reputation: 13

Regular expression Skip message to,from patterns

I have this string in php i want to skip the ppattern

------------------------------------------
FROM:Andy;
SENT:Mon, Jun 18 2012 1:52pm
TO:Ali;

------------------------------------------
FROM:Ali;
SENT:Mon, Jun 18 2012 12:26pm
TO:Andy;

Some message text here

I want to use regular expression to skip first two patterns and return only "Some message text..." there can be more of above two pattern. In PHP

Upvotes: 1

Views: 59

Answers (2)

buckley
buckley

Reputation: 14099

.*TO:.*;\s*(.*)

Be sure to set dot matches newline

In php (preg) this becomes

if (preg_match('/.*TO:.*;\s*(.*)/s', $subject, $regs)) {
    $result = $regs[1];
} else {
    $result = "";
}

Upvotes: 0

Ωmega
Ωmega

Reputation: 43683

To be 100% sure you are okay, use pattern /^.*\nSENT:[^\n]*\nTO:[^\n]*\n\n(.*)$/is

See and test the code here.


In case you migh have some whitespace characters in empty line after last "TO:" line, then use regex /^.*\nSENT:[^\n]*\nTO:[^\n]*\n\s*\n(.*)$/is

Upvotes: 1

Related Questions