- 1 year ago
Code to automatically remove users that have numbers from 1-500 at the end
To automatically remove users that have numbers from 1-500 at the end of their usernames, you can use regular expressions in Python. Here's an example:
pythonimport re
# Usernames list
usernames = [
"johnsmith",
"jane_doe123",
"mark22",
"alice123",
"robert",
"david100",
"sarah500"
]
# Pattern to match usernames with numbers from 1-500 at the end
pattern = r"\d{1,3}$"
# Filter the usernames
filtered_usernames = [username for username in usernames if not re.search(pattern, username)]
# Display the filtered usernames
for username in filtered_usernames:
print(username)
In this example, we define a list of usernames in the usernames
variable. We then define a regular expression pattern r"\d{1,3}$"
to match usernames with numbers from 1-500 at the end. The \d{1,3}
part matches 1 to 3 digits, and the $
anchors the pattern at the end of the string.
We use a list comprehension to filter out the usernames that match the pattern. The filtered usernames are stored in the filtered_usernames
list. Finally, we display the filtered usernames using a loop.
Running this code will give you a list of usernames that do not have numbers from 1-500 at the end. You can adjust the regular expression pattern or modify the code to fit your specific requirements.