Sjayo2
Sjayo2

Reputation: 21

Regex for a single string in a sentence?

How do I only use python from <:python:456490778085163011>

Upvotes: 1

Views: 43

Answers (1)

MaNKuR
MaNKuR

Reputation: 2694

Try this without using re.

'<:python:456490778085163011>'.split(':')[1]

Using re

def printWord(txt):
    resp = re.match('^<:(?P<word>\w*):\d+>\w*$', txt)
    if resp:
        print(resp.group('word'))

printWord('<:python:456490778085163011>')
printWord('<:java:4564907324085163011>')
printWord('<:anyword:456490778085163011>')

Hope it will help!

Upvotes: 1

Related Questions