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?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Jordan Smart's avatar
11
Jordan Smart
asked 7 years ago
Wingware Admin's avatar
255
Wingware Admin
updated 6 years ago

Comments

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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Wingware Support's avatar
4.2k
Wingware Support
answered 7 years ago
Wingware Admin's avatar
255
Wingware Admin
updated 6 years ago
link

Comments

Thanks, that'll work great!

Jordan Smart's avatar Jordan Smart (7 years ago)
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

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)