2021年3月9日星期二

How to extract only the digits and print as a string

Here I want to extract 011700 (these are 6 digit codes) which I want to extract without the semi-colon and later I will use a dict for a value against it.

How do I extract only 011700 (or 6 digit number from that line)? And how to print it as a 6 digit number - instead of printing it like ['011700']?

Thanks.

import re            line = "N    011700;      3;20:34:00:02:ac:07:e9:d5;2f:f7:00:02:ac:07:e9:d5; 3333"  line_list = line.split()  print(line_list)  result = (re.findall('\\d+', line))  print(result)  
https://stackoverflow.com/questions/66498371/how-to-extract-only-the-digits-and-print-as-a-string March 06, 2021 at 03:16AM

没有评论:

发表评论