Re: REGEX query

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

 



Hi,

Saturday, February 4, 2006, 2:53:32 PM, you wrote:
p> Hi,

p> I'm still trying to get to grips with REGEX and have hit a hurdle with
p> the following:

p> I have this bit of text:
p> (\(EX\) RV-6 )

p> I want to remove the '\(EX\)' part of it
p> so leaving just: ( RV-6 )

p> Any suggestions would be most appreciated.

p> Thanks
p> Alexis


I would use preg_replace_callback() for something like this:
(untested)

<?php

$string = 'some text (\(EX\) RV-6 ) and the end.';

fumction cb($data){
 $r = $data; //just in case not good format
 $parts = split(' ',$data);
 if(count($parts) > 1){
   $r = '( '.$parts[1].' )';
 }
 return $r;
}


$new_string = preg_replace_callback('/\(\\\(\w+\\\)\s[\w-]+\s\)/s','cb', $string);

-- 
regards,
Tom

-- 
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