Fairly simple problem that I've been scratching my head with regex patters for too long.
Problem: Determine if a message is a forwarded message (Subject: FT.*). If so, strip off everthing above (and including) that line and return the rest.
Constraints: Must work for both Windoz and Unix newlines ('\r\n' and '\n' respectively).
Assume the greediness is the use of both 'm' and 's' modifiers....
Here's part of the message. Note: can't rely on the ---Original Message--- line. This particulary message is from a Windoz environment, hence there are both '\r' and '\n' as EOL character.
From: Orders [orders@smallelectrics.com]
Sent: Thursday, September 28, 2006 9:30 PM
To: Tony Birnseth
Subject: FW: Order 22619 from catalog smallelectrics
-----Original Message-----
From: Patty Person (through Yahoo! Store Order System) [mailtoattyperson@junk.net]
Sent: Thursday, September 28, 2006 2:30 PM
To: orders@smallelectrics.com
Subject: Order 22619 from catalog smallelectrics
Also note that since you are single-quoting your regex, you don't need to escape the back-slashes before your \r and \n escape sequences. (Bokeh correctly changed them, I just wanted to explicitly point it out in case you didn't catch that.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Assume the greediness is the use of both 'm' and 's' modifiers.
"*" is a greedy quantifier by default whereas "*?" is lazy. This means they match as much (greedy) or as little (lazy) as possible. If there is only one match both methods will find that one match, but if there is more than one match each method will find a different match.
Originally Posted by NogDog
you don't need to escape the back-slashes before your \r and \n escape sequences.
That's right but in this instance the end result is the same:
Bookmarks