tags:

views:

58

answers:

1

Hi,

Here's what I'd like to do with a regular expression: 2 steps:

(1) transform all variables in a selected area like this:

$Sejour_deb_mois
$Info_pays

to :

$SejourDebMois
$InfoPays

(2) transform all variables in a selected area like this:

$this->Sejour_deb_mois
$this->Info_pays

to :

$this->SejourDebMois
$this->InfoPays

And I'm pretty sure this can be done using a regular expression... but I can't figure out the two good ones that do the job...

Any help would be greatly appreciated!

Thanks

Olivier Pons

+5  A: 

For both of the examples above, this should do the job:

s/\(_\)\(.\)/\u\2/g

Basically, it's finding every underscore and the following character, grouping them with the parens. Then, it discards the underscore and uppercases the one character.

If you've visually selected the region and pressed :, the whole expression will look like:

:'<,'>s/\(_\)\(.\)/\u\2/g
Curt Nelson
You'll need a : in front of the first example; Very good answer.
Kimball Robinson
This doen't work for all, because here's the problem : $this->Nom = mb_ereg_replace("[\\,\",/]","",stripslashes(strtoupper($this->Nom)));changes mb_ereg_replace to mbEregReplace
Olivier Pons