Let’s say you need to validate strings in Python. Making decisions if a string is valid or not, is what we will be looking at today.
We have a string that will look like this:
abc section will always be 3 random string characters and the integers, will always be 32 integer characters, the rest will always stay the same.
re library, we will create our regex expression and match them up with a input string, then if they are the same, we will pass the validation check, and make a decision from there.
Our random string generator:
1 2 3 4 5 6 7
Our validation check:
1 2 3 4 5
Doing the validation check against our data:
1 2 3 4 5 6 7 8 9 10 11
The function checks for a strict 32 characters in the random hex number, if you had to randomize the length, you can always use this regex: