I am trying to check for specific format to be true and the function to return either 1 or 0 if the format is correct or incorrect. Format that I am trying to use would be numbers separated with commas and spaces (i.e.
0, 13, 24, 27). My current code works to some extent, but it does not detect that only one space is in front of a number and if I were to add some random text in the middle (i.e.
0, 13, 24asd, 27), it still detects this as a valid format. How should I go about fixing this?
def format_placement(string): is_correct = 0 pattern = re.compile(r'(\d+)(?:,(\d+)*)') if re.findall(pattern, string): is_correct = 1 return is_correct