Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-07-2010, 07:40 PM   #1
Registered: Feb 2010
Posts: 40

Rep: Reputation: 15
Weird Regular Expression Notation for Visa Credit Card


I came across this regular expression via the site

I can't seem to understand it:

Specifically, I can't comprehend the part with the '?:'. As far as I'm aware, this wouldn't work because the '?' matches the previous token, which is an opening quote in this case. The colon, by my reasoning, doesn't belong in an expression matching credit cards.

Despite the strange syntax, this appears to work. Anyone have any thoughts on why?


Last edited by mattseanbachman; 03-07-2010 at 07:42 PM. Reason: cleared up ambiguity
Old 03-07-2010, 08:05 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
The '?:' is so that the parentheses don't generate backreferences. This is irrelevant if you are only using grep, but in a language like perl the backreferences are used to capture substrings from the match.

Last edited by neonsignal; 03-07-2010 at 08:07 PM.
1 members found this post helpful.
Old 03-07-2010, 09:04 PM   #3
Registered: Feb 2010
Posts: 40

Original Poster
Rep: Reputation: 15
Alright, thanks for the info. I'll have to look further into what these "back-references" entail. Until now, I've never heard of them. But as you mentioned, I'm mostly just grepping for things and using them in the context of recovering data from a seized hard drive.

Thanks again.
Old 03-07-2010, 10:37 PM   #4
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
Beware, this egular expression is used to identify a string as a possible credit card number, however it does not verify it is a real credit card number. To do that, the algorithm is more complicated, and I doubt whether it can be done with a regular expression. is a starting point, more links on that page.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Visa to Turn Android, Nokia Phones Into Credit Cards LXer Syndicated Linux News 0 09-27-2008 07:50 AM
convert a logical expression to reverse Polish notation in Java manolakis Programming 9 08-25-2008 08:45 AM
Need help with a regular expression abefroman Programming 2 05-28-2008 10:17 PM
regular expression in lex's notation browneyes Programming 1 10-04-2004 05:43 PM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 09:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration