First time here? Check out the FAQ!

Revision history  [back]

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?

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?

String Methods in Regex Find and Replace

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

from:
exampleVariable​

to:

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:

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?