查找匹配的整个单词
Find whole word for matching
我正在尝试获取正则表达式模式以查找与 word\special 字符匹配的整个单词
text = Details of Test-3K9Y9Y1-My-Node1 give me
我想从句子中得到Test-3K9Y9Y1-My-Node1
我试过了:
>>> match = re.findall('(?<=-)\w+', text)
>>> match
['3K9Y9Y1', 'My', 'Node1']
text = 'Details of Test-3K9Y9Y1-My-Node1 give me'
s=text.split(' ')
for i in s:
if '-' in i:
print(i.split('-')
您可以尝试使用以下正则表达式:
>>match = re.findall('[^ ]*-[^ ]*', text)
你可以试一试here
我正在尝试获取正则表达式模式以查找与 word\special 字符匹配的整个单词
text = Details of Test-3K9Y9Y1-My-Node1 give me
我想从句子中得到Test-3K9Y9Y1-My-Node1
我试过了:
>>> match = re.findall('(?<=-)\w+', text)
>>> match
['3K9Y9Y1', 'My', 'Node1']
text = 'Details of Test-3K9Y9Y1-My-Node1 give me'
s=text.split(' ')
for i in s:
if '-' in i:
print(i.split('-')
您可以尝试使用以下正则表达式:
>>match = re.findall('[^ ]*-[^ ]*', text)
你可以试一试here