import re
test_string = 'a1b2cdefg'
matched = re.match("[a-z][0-9][a-z][0-9]+", test_string)
is_match = bool(matched)
print(is_match)
import re
regExPattern = re.compile("[0-9]")
input1 = "5"
if not re.fullmatch(regExPattern, input1):
print("input is not a single digit")
# Example from https://docs.python.org/3/howto/regex.html
import re
p = re.compile('ab*')
p.match(input1)
# Step-By-Step breakdown:
import re # We need this module
# First make a regex object containing your regex search pattern. Replace REGEX_GOES_HERE with your regex search. Use either of these:
regex_obj = re.compile(r'REGEX_GOES_HERE', flags=re.IGNORECASE) # Case-insensitive search:
regex_obj = re.compile(r'REGEX_GOES_HERE') # Case-sensitive search
# Define the string you want to search inside:
search_txt = "These are oranges and apples and pears"
# Combine the two to find your result/s:
regex_obj.findall(search_txt)
#And it wrapped in print:
print(regex_obj.findall(search_txt)) # Will return a LIST of all matches. Will return empty list on no matches.