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

Recommended Answers

re.search returns a 'match object' or None. Follow this example
[code=python]

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'
[/code]

Jump to Post

All 2 Replies

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.