April 12, 2013 at 1:50 pm
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
April 12, 2013 at 2:10 pm
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 15, 2013 at 7:54 am
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.
April 15, 2013 at 8:31 am
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
April 15, 2013 at 8:38 am
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply