Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

STATE MACHINES AND REGULAR EXPRESSIONS PLEASE DOUBLE CHECK, AND VERIFY YOUR ANSW

ID: 3839784 • Letter: S

Question

STATE MACHINES AND REGULAR EXPRESSIONS

PLEASE DOUBLE CHECK, AND VERIFY YOUR ANSWER BEFORE SUBMITTING.

You have been hired by Gell - a company that builds computers and electronic devices to help them build a new warranty self service portal. One of your tasks is to an up-front validation of the serial number entered on the web site before we go to the database to get the specifics on this computer/device. Unfortunately, each division of the company has a different idea on what a serial number should look like. The System Architect has decided that you need to create a single regular expression that will match ONLY the following serial number patterns:

Computer serial numbers start with a consonant, then a vowel (never y), a dash, then 6 digits. Examples: XA-123456 CU-987654 BO-062021

GPS's have 1-8 digits then 2-4 characters. Examples: 1BB 18273645QZ

Toys use 5 digits, a comma, then 5 more digits. Examples: 12345,98765 35481,01257

Cell Phones use a three digit carrier code, a colon, two characters, a greater than sign then 7 digits. Examples: 321:BB>1234567 332:QG>3948571

All letters are upper case. Please test your regex thoroughly.

Explanation / Answer

^(([^aeiouAEIOU][aeiouAEIOU]-d{6})|(d{1,8}[a-zA-Z]{2,4})|(d{5},d{5})|(d{3}:[a-zA-Z]{2}>d{7}))$

This will match all those patterns.

Doesn't support newlines though. That shouldn't be a problem.