SQLServerCentral.com / SQL Server 2005 / CLR Integration and Programming. / RegEx CC / Latest PostsInstantForum.NET v2.9.0SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comTue, 31 Mar 2015 16:12:01 GMT20RE: RegEx CChttp://www.sqlservercentral.com/Forums/Topic1441906-386-1.aspxI 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.[code]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("-", ""));[/code]Mon, 15 Apr 2013 08:38:23 GMTSean LangeRE: RegEx CChttp://www.sqlservercentral.com/Forums/Topic1441906-386-1.aspxI 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.Mon, 15 Apr 2013 08:31:53 GMTOrlando ColamatteoRE: RegEx CChttp://www.sqlservercentral.com/Forums/Topic1441906-386-1.aspxThanks 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.Mon, 15 Apr 2013 07:54:02 GMTLaura_SqlNoviceRE: RegEx CChttp://www.sqlservercentral.com/Forums/Topic1441906-386-1.aspxNow 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.[url=http://www.regular-expressions.info/creditcard.html]http://www.regular-expressions.info/creditcard.html[/url]Here is another one:[code]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})$"; [/code]A quick google/bing should reveal thousands of examples.Fri, 12 Apr 2013 14:10:48 GMTSean LangeRegEx CChttp://www.sqlservercentral.com/Forums/Topic1441906-386-1.aspxHi 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,LauraFri, 12 Apr 2013 13:50:46 GMTLaura_SqlNovice