我有一个字符串列表,如下所示:
['MEASUREMENT K02313 New York',\
'MEASUREMENT K02338 London [BC:2.7.7.7]',\
'MEASUREMENT K14761 Kairo [BC:1.2.-.-]',\
'MEASUREMENT K03629 Berlin',\
'MEASUREMENT K02470 Paris [BC:5.6.2.-]',\
'MEASUREMENT K02469 Madrid [BC:5.43.2.2]',\
....]
As you can see some elements in the list have a string with the format BC:x.x.x.x, with x either being a number from 0-999 or a hyphen ("-").
Now I want to get a seperate list that has all of these BC:x.x.x.x elements saved.
I tried using a regular expression:
re.findall(r"BC:([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|-).([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|-).([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|-).([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|-)", list_name)
但它不起作用,我收到以下错误消息:
TypeError: expected string or bytes-like object