Simple regex required
I've never used regex in my life and it seemed to look like a deep pool to dive into. Anyway, I need a regex for this pattern (AN is alphanumeric (az or 0-9), N is numeric (0-9), and A is alphabetic (az)):
AN,AN,AN,AN,AN,N,N,N,N,N,N,AN,AN,AN,A,A
It's five ANs, followed by six Ns, and then three ANs, and then finally two A.If it matters, the language I'm using is Java.
[a-z0-9]{5}[0-9]{6}[a-z0-9]{3}[a-z]{2}
should work in most RE dialects for tasks as you pointed it out - most will also support abbreviations such as \d
(digit) instead [0-9]
(but if alphabets are supposed to be lowercase seem to be asking, you will probably need to specify parts a-z
) ...
a source to share
For the example you posted, the following should work fine.
(([A-Za-z\d])*,){5}+(([\d])*,){6}+(([A-Za-z\d])*,){3}+([\d])*,[\d]*
In Java, you can use it like this:
boolean foundMatch = subjectString.matches("(([A-Za-z\\d])*,){5}+(([\\d])*,){6}+(([A-Za-z\\d])*,){3}+([\\d])*,[\\d]*");
I used this tool to help you learn RegEx and it's very easy to do. http://www.regexbuddy.com/
a source to share