TOgakangaroo Posted March 24, 2008 Share Posted March 24, 2008 While writting this post I realized the problem but I still don't have a solution - I need a lookbehind of variable width - all the text that follows a line that contains a certain format, how do I do I get around this limitation? Here are the contents of my previous post with my example: Hi guys, I'm going nuts with this problem. Im simply trying to pull out the contents of a string following a certain string type. Here's my sample program: <?php $str = "Date: Thu 20-Mar-2008 13:41:37 Location: PHILADELPHIA User: ABCDE Please change densitites to 12.88 for tank 1353 for rec # 1234 and for all shipments from 3/19/08 to present. I did change tank density. Thanks "; $pattern = '/(?<=(User:\s*\w*\S)).*/sm'; if(preg_match($pattern, $str, $matches)) {printpre($matches); } else { printpre("Matches Not Found"); } function printpre($var) {print("<pre>");print_r($var);print("</pre>");} ?> To my understanding, $pattern should match all text preceeded by (User:<some spaces><some letters><some whitespace>) which should be the whole message part of the search string (following the 'User: ' line). The results however: "Matches not found". Oddly, the following works: $pattern = '/(?<=(User: \w\w\w\w\w\s)).*/sm'; Quote Link to comment Share on other sites More sharing options...
effigy Posted March 24, 2008 Share Posted March 24, 2008 <pre> <?php $str = "Date: Thu 20-Mar-2008 13:41:37 Location: PHILADELPHIA User: ABCDE Please change densitites to 12.88 for tank 1353 for rec # 1234 and for all shipments from 3/19/08 to present. I did change tank density. Thanks "; list($metadata, $data) = preg_split('/User:\s*\S*\s+/', $str); echo $data; ?> </pre> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.