I'm trying to setup a regex that will look for specific 'markers' and perform actions on the text between the markers, but I'm finding it a lot more difficult then I think it should be. So, I figured I'd post my problem here, as I've always gotten speedy and helpful responses on these forums.
Let's say my preg_replace pattern is:
"L1 (.*) L2"
And in the variable I'm searching I have numerous instances of this, such as:
"L1 this is some text, possibly with some new lines L2"
"L1 this is some more text L2"
So when it searches it finds the first L1 just fine, but it uses the second L2, so it wouldn't treat the above text as two separate search/replaces, it would treat them as one using L1 from the first line and L2 from the second, grouping them both together.
I realize this is probably because (.*) matches new lines, white space, etc., but is there any way to easily have it match on the first instance of L2 that it finds instead of the last one in the variable I'm searching?
If someone can point me in the right direction I'd be sooo happy.
This is exactly what I'm trying to do:
$pattern = "L1 (.*) L2 (.*) L3";
if (preg_match("/$pattern/", $template, $matches)) {
$temp_text_1 = $matches[1];
$temp_text_2 = $matches[2];
-- then do some stuff with the matches here --
}