Re: Regex Help
| From: | Curt Zirzow | Date: | Mon, 10 May 2004 22:54:14 +0000 |
| Subject: | Re: Regex Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185870@lists.php.net to get a copy of this message | ||
* Thus wrote hitek (hitek@cox.net):
> Greetings list,
>
> I have been given a list of products, and I need some help building a
> regular expression to split the category from the sub category.
> Example:
> CamerasDigital_CannonXLRshot <-Original entry in list
> Cameras Digital Cannon XLRshot <-Desired result.
One possiblity:
echo preg_replace('/([a-z])_?([A-Z])/', '$1 $2',
'CamerasDigital_CannonXLRshot');
explanation:
match a lower case character preceding an uppercase character,
with an optional underscore between them. Replace that match with
the matched lowercase character, space and matched uppercase character.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."