((ba)*b+)*
Regular Expression (Delimit with quotes) |
|
String (Delimit with quotes) |
|
Find a regular expression that matches price tag amounts: a dollar sign, a dollar amount consisting of one or more digits 0 through 9, optionally followed by cents, but always a decimal point and two digits if cents are included. If a 0 immediately follows the dollar sign, then the dollar amount consists of only that digit.
Accepted:
$45 $149.99 $199.03 $0.12 $0.00 $0
Not Accepted:
$49.1 149.99 $.49 $149.499 $00.45 $000
You will have to
escape the dollar sign by placing a backslash in front of it: \$
Do the same with the decimal point.
Hint: the RE is in three parts. First a part that matches the dollar sign, then a part that matches the dollars, finally an optional part that matches the decimal point and cents. You may find it helpful to draw a finite automaton, and then to write the regular expression.
Construct a RE that matches price strings.