I have to split an email that is received everyday, with a set of rules. This is an example of the email:
A N K U N F T 11.08.15
*** NEUBUCHUNG ***
11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F882129 dsdsaidsaia
F882129 xxxyxyagydaysd
«CUT HERE»
A N K U N F T 18.08.15
*** NEUBUCHUNG ***
11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F881554 ZXCXZCXCXZCCXZ
F881554 xcvcxvcxvcvxc
F881554 xvcxvcxcvxxvccvxxcv
«CUT HERE»
11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F881605 xczxcdfsfdsdfs
F881605 zxccxzxzdffdsfds
«CUT HERE»
So it basically has to be cut whenever the last F999999 appears ( where 9 can be any number). How can I do this?
I tried the solution on a regex101.com - https://regex101.com/r/rT0yQ1/1 and it worked, however when I do this on my server with php and sending the email text by post is doesnt. I paste the email text to a textbox and then press a button that then divides it. Here is my code: file teste.php:
<form method="post" action="teste2.php" enctype="multipart/form-data">
<textarea name="email" cols="110" rows="30" id="email"></textarea>
<br />
<input type="submit" value="Dividir" />
</form>
file teste2.php
<?php
$str = $_POST['email'];
$re = "/(?:\sF\d+.*?\n\n)(\n)/";
$subst = ">>CUT HERE>>";
$result = preg_replace($re, $subst, $str);
echo $result;
?>
I try this here: https://3v4l.org/mqrJc and it works. It seems like a problem when I send the text in a textarea by post, Because If I use a string it works. Can anyone help me? Thank you very much in advance!