I'm confused by your reply
Who, me, confusing? :-) The original problem is that
where there is only one pair of brackets but if there are many pair or brackets , like the following , it doesn't work :
Greedy pattern matching causes the regexp to go all the way to the second pair of brackets encompassing the entire line from the date bracket to the
second brackets, that's the original problem. Running the code in the previous post clearly demonstrates the issue.
Why are you using preg_replace for one thing?
As an example of extracting ONLY the date or usage of preg to extract the date and other sub strings, and to demonstrate proper functioning of the regex.
The example regexp I posted actually wouldn't work:
It does, but as said, it's because it's missing the
quantifier which stops greedy pattern matching.
The two differences between your mod
'/^\[([^]]*)\]/'
and mine
'/^\[([^\]]+)\]?.*/'
is that + means "one or more of the preceding" and * means "zero or more of the preceding" which will allow it to match on
[]
Which, of course, is an impossibility in an error log (I think . . . ) in the spirit of TMTOWTDI your solution should be fine.
The second difference is the quantifier which stops greedy pattern matching, ? and .*which only becomes useful If you wish to store anything after the initial bracketed date, as in "Three, save error:", the last example above.
Always TMTOWTDI, always fun. :-)