A regular expression will do the trick with very little code:
import re
...
if re.match("^[A-Za-z0-9_-]*$", my_little_string):
# do something here
More Related Contents:
- Removing contents within brackets in string [duplicate]
- Regex not matching all the paranthesis substrings [duplicate]
- How to understand regular expression with python?
- How to extract numbers from a string in Python?
- Speed up millions of regex replacements in Python 3
- Is there a simple way to remove multiple spaces in a string?
- How to correctly sort a string with a number inside? [duplicate]
- Split string on whitespace in Python [duplicate]
- Fast punctuation removal with pandas
- Python regex – r prefix
- How to input a regex in string.replace?
- Split a string at uppercase letters
- How can I do multiple substitutions using regex?
- Python regex match OR operator
- Find longest repetitive sequence in a string
- How to match any string from a list of strings in regular expressions in python?
- How to extract an IP address from an HTML string?
- Extract a string between double quotes
- Regex for existence of some words whose order doesn’t matter
- How would I get everything before a : in a string Python
- Python regex: splitting on pattern match that is an empty string
- Remove duplicate chars using regex?
- How to remove symbols from a string with Python? [duplicate]
- How can I split this comma-delimited string in Python? [duplicate]
- Replace a string located between
- Remove Sub String by using Python
- FutureWarning: The default value of regex will change from True to False in a future version
- How to use str.contains() with multiple expressions in pandas dataframes
- Splitting a math expression string into tokens in Python
- Adding characters after a certain word in Python using regex