Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

RegEx CC Expand / Collapse
Author
Message
Posted Friday, April 12, 2013 1:50 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 31, 2014 7:40 PM
Points: 103, Visits: 500
Hi Guys,

What I need to do is find rows that may have credit card in the text. Here is the regular expression I am using, but this one ignores the ones with space or hyphens.

(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})

What I need to do is:
Find character string that may have CC#s and the CC# might have space, hyphen or no delimeters between the group of numbers. The regex should work with all major CCs. The CC#s will be somewhere in between the text not at the start.

For example: "blah blah... 4258-1234-5678-1234. Email sent blah blah..."

The RegEx should catch the above string as the string of numbers look likes Visa CC #.

Anyone who has such RegEx?

Thanks,
Laura

Post #1441906
Posted Friday, April 12, 2013 2:10 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:10 AM
Points: 13,082, Visits: 12,546
Now that you decided to go full on CLR for this you have a myriad of resources for your searches. I found this one which looks pretty good.

http://www.regular-expressions.info/creditcard.html

Here is another one:

string ccRegEx = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$"; 

A quick google/bing should reveal thousands of examples.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1441920
Posted Monday, April 15, 2013 7:54 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 31, 2014 7:40 PM
Points: 103, Visits: 500
Thanks Sean for the response. I tested many regExes I found in google, but I couldnt find the one which will work with a char string where it will have CC# somewhere in the string that has alphanumeric characters as well as special characters.
Post #1442307
Posted Monday, April 15, 2013 8:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:06 PM
Points: 7,125, Visits: 12,720
I am not in a place where I can test, but it seems like simply adding a .* before and after the regex that matches your CC# pattern would make it work for any string.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1442328
Posted Monday, April 15, 2013 8:38 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:10 AM
Points: 13,082, Visits: 12,546
I think we can do it like this. Basically we just use a word boundary and a simple replace. This will find any values with numbers between 13 and 16 characters. Unless you have other long numeric values you shouldn't get too many false positives.

string ccRegEx = @"\b\d{13,16}\b";
string SomeValue = "this contains possible CC Nums 1234-5689-9875-5621 or so it seems.";
SomeValue = "blah blah... 4258-1234-5678-1. Email sent blah blah...";
Regex r = new Regex(ccRegEx);
bool found = r.IsMatch(SomeValue.Replace("-", ""));



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1442334
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse