简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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