簡體   English   中英

查找整個單詞進行匹配

[英]Find whole word for matching

我試圖讓正則表達式模式找到整個單詞,如果它匹配一個單詞\\特殊字符

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)

你可以在這里試試

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM