I have a python script that takes input using a pattern like this:
1** then takes multiple inputs after that like 100, 110, 011 ect.
I need to test to see if the imputed data matches the pattern, the * can stand for either a 1 or a 0. What is the best way to go about doing this? I’m fairly new to Python, so explanations would be helpful.
Update: added input and output example
Example of correct input and output:
input:
**1 (pattern)
001, 101, 000
output:
001, 101
I would suggest using the input string and
replaceto generate a simple regular expression:Now that can be used in whatever way you want:
If you aren’t familiar with regular expressions, you might want to read a tutorial or two. But the fundamental idea is that any one of the characters between brackets is allowed. So a
[01]matches either a 1 or a 0, as you requested in your question.