python: regex match credit card starting with fixed letters

Question:

I want to write a regex that matches the following credit card that starts with fixed letters, e.g,

examples = ['AU01 0000 1234 5678 9012 00', 'AU01 3200 1564 5678 9987 55']

I have written the following regex but it does not capture the letters ‘AU’.

regex = r'(?:(w*AU)[0-9]{4}s){3}[0-9]{4}|[0-9]{16}|[0-9]{2}'
Asked By: zara kolagar

||

Answers:

This expression will include the starting A and U once each and then look for 4 combinations of 4 digit numbers and then a combination of 2 digit number at the end:
AU(d{4}){4}(d{2}).

NOTE : You’ll need to remove the spaces from the strings in order to match this expression.

Answered By: Darshil Jani
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.