Ask Your Question
1

String Methods in Regex Find and Replace

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

Jordan Smart gravatar image

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

Wingware Admin gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

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

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

Wingware Admin gravatar image

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.

edit flag offensive delete link more

Comments

Thanks, that'll work great!

Jordan Smart gravatar imageJordan 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

2 followers

Stats

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

Seen: 28 times

Last updated: Mar 07