Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. def get_real_mac(sentence):
  2. # Here, I assume that MAC address is seperated by a colon, or by a dash, but not by both.
  3. colon_pattern = r'[0-9abcde]{2}:[0-9ABCDEF]{2}:[0-9ABCDEF]{2}:[0-9ABCDEF]{2}:[0-9ABCDEF]{2}:[0-9ABCDEF]{2}'
  4. colon_matches = re.findall(colon_pattern, sentence, re.IGNORECASE)
  5.  
  6. dash_pattern = re.sub(r':', r'-', colon_pattern)
  7. dash_matches = re.findall(dash_pattern, sentence, re.IGNORECASE)
  8.  
  9. rt_list = colon_matches + dash_matches
  10. if rt_list:
  11. return rt_list[0]
  12. return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement