简体   繁体   English

查找整个单词进行匹配

[英]Find whole word for matching

I am trying to get the regex pattern to find whole word if it matches a word\\special character我试图让正则表达式模式找到整个单词,如果它匹配一个单词\\特殊字符

text = Details of Test-3K9Y9Y1-My-Node1 give me

I want to get Test-3K9Y9Y1-My-Node1 from the sentence.我想从句子中得到Test-3K9Y9Y1-My-Node1

I tried:我试过:

>>> 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('-')

You could try to use the following regular expression:您可以尝试使用以下正则表达式:

>>match = re.findall('[^ ]*-[^ ]*', text)

And you could try it out here你可以在这里试试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM