Re: Regex help needed...

From: Date: Mon, 12 Feb 2001 23:02:33 +0000
Subject: Re: Regex help needed...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39282@lists.php.net to get a copy of this message
on 2/12/01 4:30 PM, Christian Reiniger at creinig@mayn.de wrote: > On Monday 12 February 2001 21:08, Jesse Swensen wrote: >>>> This should be a quick one, but I can't seem to wrap my brain around >>>> it. All I need to do is replace leading or trailing spaces with >>>> underscores. If there is spaces in between words, leave them alone. >> but I wanted to convert each space to a "_", then what? I tried: >> >> $fix = ereg_replace("(^ +)|( +$)", "_", $checkme); >> >> and >> >> $fix = ereg_replace("(^[ ]+)|([ ]+$)", "_", $checkme); > > preg_match ('/^(\s*)(.*?)(\s*)$/', $checkme, $matches); > $NewString = str_repeat ('_', strlen ($matches [1])). > $matches [2] . > str_repeat ('_', strlen ($matches [3])); > > not tested, but should work fine. That worked. Thank you very much. -- Jesse Swensen swensenj@bellsouth.net

« previous php.general (#39282) next »