Ask Your Question

String Methods in Regex Find and Replace

asked 2018-03-09 14:01:00 -0500

Jordan Smart's avatar

updated 2019-03-13 08:34:16 -0500

Wingware Admin's avatar

I'm trying to convert between variable naming conventions, from:




I can find the relevant variables with the regex search "([a-z])([A-Z])", and use "\1_\2" to convert to "example_Variable", but to convert to the desired convention using re.sub() would require something like:

re.sub('([a-z])([A-Z])',lambda match:"_",'exampleVariable')​

However, simply placing the inline function in Wing's replace line doesn't achieve the desired effect. Is there an alternative way to accomplish what I'm looking to do?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-03-09 14:37:00 -0500

updated 2019-03-07 09:05:14 -0500

Wingware Admin's avatar

In Wing Pro there are "Symbol To *" refactoring operations for converting between UpperCamelCase, lowerCamelCase, under_score_name, and UNDER_SCORE_NAME forms.  To use that, click on the symbol an use the items in the Refactor menu or right click to get a menu that includes a Refactor group.  This will change all points of use of that symbol, whether in the current file or not so is probably a lot easier to use than search/replace.

If you do need to write code for the conversion, you'ld have to do it via the scripting API which is documented at probably by operating directory on the CAPIDocument.

edit flag offensive delete link more


Thanks, that'll work great!

Jordan Smart's avatar Jordan Smart  ( 2018-03-09 15:01:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-03-09 14:01:00 -0500

Seen: 942 times

Last updated: Mar 07 '19