PDA

View Full Version : Preg_match Matching only on a new line?


MTGDarkness
03-22-2009, 01:47 AM
I have this code:
$mepattern = '/\/me([^\r\n]+)/is';
if(preg_match($mepattern, $this->post['message']))

It's half the /me hack that I downloaded. However, it got greedy and started detecting all /mes. Annoying when you're using URL rewrites and one of your forums is named metaboard... :down: Basically, I need it to only detect /mes at the beginning of a new line. :( And I am really bad with Regex. Also, what does that one snippet ([^\r\n]+)/is mean?

Dismounted
03-22-2009, 05:24 AM
You want it to be ungreedy, so add the modifier: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

MTGDarkness
03-22-2009, 09:24 AM
Perhaps greedy was the false term for it...