Replacing "[A-Z]" to "_[A-Z]"

Find, replace, find in files, replace in files, regular expressions

Replacing "[A-Z]" to "_[A-Z]"

Postby httptunnel » Fri Jun 02, 2006 9:09 am

Hello,

I am trying to change all uppercase letters so they get preceded by a "_" character.

I have been able to find uppercase letters (using "[A-Z]" and checking the 'match case' box) but they get replaced by "_[A-Z]" instead of the found letter preceded by the "_".

What syntax should I use?

Thanks a lot!!
User avatar
httptunnel
Newbie
 
Posts: 3
Joined: Thu Jun 01, 2006 11:00 pm

Re: Replacing "[A-Z]" to "_[A-Z]"

Postby Bego » Fri Jun 02, 2006 9:30 am

In Perl regexp (see your options) find:
([A-Z])
replace with:
_\1

Of course the regexp-checkbox in find dialog has to be set.

But I found out a strange behaviour: This search is dependant of the switch "ignore big/small characters" in the search dialog !!!

If you switch to the meaning a=A, the regexp [A-Z] also finds a small "a" !?!?

I thought when choosing regexp this switch should be ignored, since [a-z] would explicitly only find small letters ...

Is it a feature ?

12.10+3

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Replacing "[A-Z]" to "_[A-Z]"

Postby httptunnel » Fri Jun 02, 2006 9:58 am

Hi Bego,

Thanks for your fast response, It is working for me now!! I had already tried that, but without the parenthesis (so it wasn't working indeed).

Now I have a further question ( I am not sure if it needs another new topic or can be done in the same one).

I would like this behaviour except por the first letter of a line. That is:
If I have "ThisIsAnExample" I need "This_Is_An_Example" instead of "_This_Is_An_Example"

Thanks a lot!
User avatar
httptunnel
Newbie
 
Posts: 3
Joined: Thu Jun 01, 2006 11:00 pm

Re: Replacing "[A-Z]" to "_[A-Z]"

Postby Mofi » Fri Jun 02, 2006 10:02 am

Bego, yes, it is a feature. [A-ZÄÖÜ] or [a-zäöü] means the same as [A-Za-zÄÖÜäöü] if the find option Match Case (English name) is not used.

The syntax language definition keyword Nocase has the same influence on the regex function strings of the language definition as the find option "Match Case".
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4068
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Replacing "[A-Z]" to "_[A-Z]"

Postby Bego » Fri Jun 02, 2006 10:15 am

Hi Mofi,
For me, I'd prefer that a "hard" [a-z] always means small characters.

httptunnel:
search: ([a-z])([A-Z])
replace: \1_\2

but it does not do: myTTTest to my_T_T_Test
it changes it to my_TTTest (an my feeling says: that's ok for you) ;-)


rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Replacing "[A-Z]" to "_[A-Z]"

Postby httptunnel » Fri Jun 02, 2006 10:53 am

Bego,

Yes, your feeling was absolutely right!! :wink: :D

It almost fits my needs except in one case. Consider this example: "MyHTMLCode".
What I need is "My_HTML_Code" and not "My_HTMLCode".

Anyway, I have few cases like this and can modify them manually. Current solution is pretty good.
(of course solutions to this are welcome :wink: )

Thanks a lot again.
User avatar
httptunnel
Newbie
 
Posts: 3
Joined: Thu Jun 01, 2006 11:00 pm


Return to Find/Replace/Regular Expressions