php - Find a regex to take part of Email -
i have following emails need extract part from:
bestellnummer xxx: 1 von xxx, 1er pack ------------- anfang der nachricht ------------- foo bar baz foo bar baz // <<<<< need text here ------------- ende der nachricht ------------- ------------- anfang der nachricht ------------- foo bar baz foo bar baz ------------- ende der nachricht ------------- there 0 unlimited occurences of
------------- anfang der nachricht ------------- ------------- ende der nachricht ------------- and i'm able extract first part regex:
$re = "/------------- .*? -------------.?(.*?).?------------- .*? -------------/s"; but, i'm quite new on learning regex, i'm pretty sure there must better regex extract part (foo bar baz foo bar baz) of text between
------------- anfang der nachricht ------------- ------------- ende der nachricht ------------- as can in different languages, i'm using
.? to match between hyphens.
i need first occurence of text no matter how many occurences there are. there more solid solution regex?
here's
demo @ regex101.com
i ended with: $regexp = '/nachricht\s-+\s+(.*?)\s+-+\sende/s';
so, saves few matching steps , bit of trimming on message.
more solid regexp.. works. write test on safe side.
\s- matches space-+- matches 1 or more-chars\s+- matches 1 or more spaces; before/after message trim message(.*?)- message
Comments
Post a Comment