I have the below method in Python (3.10):
import re
def camel_to_screaming_snake(value):
return '_'.join(re.findall('[A-Z][a-z]+|[0-9A-Z]+(?=[A-Z][a-z])|[0-9A-Z]{2,}|[a-z0-9]{2,}|[a-zA-Z0-9]'
, value)).upper()
The goal I am trying to accomplish is to insert an underscore every time the case in a string changes, or between a non-numeric character and a numeric character. However, the following cases being passed in are not yielding expected results. (left is what is passed in, right is what is returned)
vn3b -> VN3B
vnRbb250V -> VN_RBB_250V
I am expecting the following return values:
vn3b -> VN_3_B
vnRbb250V -> VN_RBB_250_V
What is wrong with my regex preventing this from working as expected?