Below simple code will extract the Twitter username from text using python re module.
import re # Extract the username without @ pattern = re.compile(r'(?<=\B@)[\w_]+') gad = pattern.findall("hello mr @gadgets") print(f'Hi, {gad}') # Hi, ['gadgets']
The Twitter username only allows words, numbers and underscore…