> ## Content Index
> Fetch the complete content index at: https://kudithipudi.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# HOW TO : Use Python to look for credit card numbers
- URL: https://kudithipudi.org/how-to-use-python-to-look-for-credit-card-numbers/
- Published: 2012-08-20T21:53:04.000Z
- Updated: 2012-08-20T21:53:04.000Z
- Description: Simple script in python to look for credit card numbers in a file. [code] #Importing modules import re import os # Define variables inputFile = ‘test.txt’...
- Author: admin
- Tags: HOWTO, Programming, security, Uncategorized, #wp, #wp-post, #Import 2026-08-23 02:32

Simple script in python to look for credit card numbers in a file.

```

#Importing modules
import re
import os
# Define variables
inputFile = ‘test.txt’
searchPattern = ‘((\D(6011|5[1-5]\d{2}|4\d{3}|3\d{3})\d{11,12}\D)|(^(6011|5[1-5]\d{2}|4\d{3}|3\d{3})\d{11,12}\D))’
tempinputFile = open(inputFile)
tempLine = tempinputFile.readline()
while tempLine:
print ("LINE: " + tempLine)
foundContent = re.search(searchPattern,tempLine, re.IGNORECASE)
if foundContent:
print("FOUND: " + foundContent.group())
tempLine = tempinputFile.readline()
tempinputFile.close()
```

The script started out as a simple check for any 16 digit numbers that had a non numeric character on either end. But I tweaked it a little bit to look for credit card like numbers using the regex from [http://www.regular-expressions.info/creditcard.html](http://www.regular-expressions.info/creditcard.html?ref=kudithipudi.org). Finally I added an option to match credit card like numbers if the numbers start at the beginning of the line (i.e there is no non-numeric number before the credit card number)