
July 11th, 2009, 02:05 AM
|
|
|
You're using the m- (multi-line) and s- (DOT-ALL) modifiers while you only need the DOT-ALL. When using the multi-line modifier, the regex meta character ^ and $ will not only match the start and end of the entire string, but also match the start and end of each line in the entire text. Since you're not utilizing these meta characters, you can leave it out. And DOT-ALL will cause the DOT to match new line characters as well (by default it doesn't). When enabling this option, you'll have to be careful with the greedy DOT-PLUS and DOT-STAR's in your regex because the entire string will be "eaten" by them! I've made them reluctant (un-greedy) by adding a question mark after them:
And I also replaced some of them with a negated character class:
which means: match one or more characters of any type, except new line characters.
So, the final regex might look like this:
PHP Code:
preg_match('/page:\s+404;(?P<URL>[^\r\n]+).*?user:\s+(?P<user>[^\r\n]+)/s', $text, $match);
|