import re
# Replace YOUR_MESSAGE with the actual message you want to check
message = "Check out https://t.me/BTC_Volatility for more information."
# Define a regular expression pattern to match a Telegram username
username_pattern = r'@([A-Za-z0-9_]+)'
# Define a regular expression pattern to match a URL
url_pattern = r'(https?://\S+)'
# Check if the message contains a username or URL
if re.search(username_pattern, message):
# Extract the username from the message
username = re.findall(username_pattern, message)[0]
print(f"Username found: {username}")
if re.search(url_pattern, message):
# Extract the URL from the message
url = re.findall(url_pattern, message)[0]
print(f"URL found: {url}")
if not re.search(username_pattern, message) and not re.search(url_pattern, message):
print("No username or URL found")
0 Comments