preg_replace problem

From: Date: Thu, 18 Jan 2001 13:01:58 +0000
Subject: preg_replace problem
Groups: php.general 
Request: Send a blank email to php-general+get-35338@lists.php.net to get a copy of this message
I have a regular expression that's not giving me the results i really need. I have a bunch of strings coming at me that need to be truncated if they're over 15 characters... but not to truncate until after it reaches the first word. This regular expression just doesn't seem to want to work 100%: $myString = preg_replace("/.{15}\w)?\s.*/","\\1",$myString); This will turn: 'PROJECT - Marketing Pitch' into 'PROJECT - Marketing\1' However... when i change it to: /(.{15}\w)+.*/ everything seems to work fine. I can't really use this regex though, because it will keep matching that 15 character word until it reaches the end. I need it to stop matching after it finds the first match (if it needs to match at all). In perl: + <- means match 1 or many times * <- means match 0 or many times ? <- means match 0 or 1 time Could someone help me see my error... i'm driving myself bananas trying to find it. Perhaps pcre in PHP doesn't support the ? in the regular expressions. Best Regards, Rob

« previous php.general (#35338) next »