I'm using re.search to search for the pattern of anything that might look like a credit card number in a file.

What I would like to do, is have the script then pull out the potential cc number and pass it to the Luhn algorithm for verification.

If I'm not mistaken, re.search only returns true or false. How can I pull out the cc number and set it to a variable?

Thanks.

Jason

re.search returns a 'match object' or None. Follow this example

>>> mo = re.search(r"b\w+", "'Give me bacon and eggs,' said the other man.")
>>> mo
<_sre.SRE_Match object at 0x7f90947e2e68>
>>> mo.group(0)
'bacon'

That worked.

Thank you much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.