Re: regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






On Thu, October 19, 2006 9:42 am, Robin Vickery wrote:
> On 19/10/06, Bagus Nugroho <bnugroho@xxxxxxxxxxxx> wrote:
>> Hi All,
>>
>> If we have variable like :
>>
>> $var1 = 'abcde 12';
>> $var2 = 'abcdefghi 34';
>> $var3 = 'abc 20 def';
>>
>> Then we want output like :
>> $var1 = 'abcde';
>> $var2 = 'abcdefghi';
>> $var3 = 'abc def';
>
>
> $re = '/^\s+|\d+\s*|\s*\d+\s*$/';
>
> $var1 = preg_replace($re, '', $var1);
>
> It may or may not be what you're after, but it handles all your
> examples.

$var = preg_replace('/[0-9]*/', '', $var);
$var = preg_replace('/\\s+/', ' ', $var);
$var = trim($var);

This also fits all the examples, and is comprehensible. :-)

Whether it's right or not still depends on a better question.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux