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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to