[英]How replace uppercase by lower and put underscore? What's my mistake?
I am trying to write two functions.我正在尝试编写两个函数。 The first is to change it:
首先是改变它:
HjhfdhHbvUj
to this对此
hjhfdh_hbv_uj
And the second function should do the opposite.而第二个 function 应该做相反的事情。
def camel_snake(str_name):
str_name.replace(([a-z][A-Z]+)|([A-Z]+[a-z]), '\L$1')
return str_name
def snake_camel(str_name):
str_name.replace('\L$1', ([a-z][A-Z]+)|([A-Z]+[a-z]))
return str_name
Please tell me how to arrange so that I do not have an error in the syntax?请告诉我如何安排,使我没有语法错误?
My teacher forbade me to use regular expressions to solve this problem.我的老师禁止我使用正则表达式来解决这个问题。 Please give me some links to read something that will help solve this problem
请给我一些链接以阅读有助于解决此问题的内容
I am trying to write two functions.我正在尝试编写两个函数。 The first is to change it:
首先是改变它:
HjhfdhHbvUj
to this对此
hjhfdh_hbv_uj
And the second function should do the opposite.而第二个 function 应该做相反的事情。
def camel_snake(str_name):
str_name.replace(([a-z][A-Z]+)|([A-Z]+[a-z]), '\L$1')
return str_name
def snake_camel(str_name):
str_name.replace('\L$1', ([a-z][A-Z]+)|([A-Z]+[a-z]))
return str_name
Please tell me how to arrange so that I do not have an error in the syntax?请告诉我如何安排,使我没有语法错误?
My teacher forbade me to use regular expressions to solve this problem.我的老师禁止我使用正则表达式来解决这个问题。 Please give me some links to read something that will help solve this problem
请给我一些链接以阅读有助于解决此问题的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.