First time here? Check out the FAQ!
1

String Methods in Regex Find and Replace

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

exampleVariable​

to:

example_variable​

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: match.group(1)+"_"+match.group(2).lower(),'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?

Jordan Smart's avatar
11
Jordan Smart
asked 2018-03-09 14:01:00 -0500
Wingware Admin's avatar
231
Wingware Admin
updated 2019-03-13 08:34:16 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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 http://wingware.com/doc/scripting probably by operating directory on the CAPIDocument.

Wingware Support's avatar
4.1k
Wingware Support
answered 2018-03-09 14:37:00 -0500
Wingware Admin's avatar
231
Wingware Admin
updated 2019-03-07 09:05:14 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks, that'll work great!

Jordan Smart's avatar Jordan Smart (2018-03-09 15:01:00 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer