Dec-01-2019, 11:29 PM
Colleagues, tell me, please, the answer to my question.
I have a variable that contains the mac address.
Here is a regular expression describing it -
For this, I wrote this code:
If I write to a variable mac value
Please tell me what am I doing wrong?
Ogogon.
I have a variable that contains the mac address.
Here is a regular expression describing it -
r'^\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}$'Now I want to one-sign bytes of address be supplemented by zero.
For this, I wrote this code:
mac = re.sub(r'^(\w):',r'0\1:',mac) mac = re.sub(r':(\w):',r':0\1:',mac) mac = re.sub(r':(\w)$',r':0\1',mac)Unfortunately, the second line of code does not replace all the substrings matching the regular expression.
If I write to a variable mac value
Quote:'1:2:3:4:5:6', then after code execution, its value
Quote:01:02:3:04:5:06
Please tell me what am I doing wrong?
Ogogon.