Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果匹配单词\特殊字符,我正在尝试让正则表达式模式找到整个单词
text = Details of Test-3K9Y9Y1-My-Node1 give me
我想Test-3K9Y9Y1-My-Node1从句子中得到。
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)
你可以在这里试试