logo CodeStepByStep logo

regex2

Language/Type: General regular expressions
Author: Melissa Hovik (on 2018/06/01)

Write a regular expression that will match each of the following patterns:

Non-negative 7-digit numbers
A 16-digit credit card number, with optional dashes for every four digits
A 16-digit credit card number, with the first digit being a 5 and the second digit being a 1, 2, 3, 4, or 5 (the rest of the digits can be anything). Do not match any dashes in this expression.
A real number such as 3.14, -0.2018, or 1 (must have a digit before and after decimal point)

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.