Write regular expressions to match the following criteria and only the following
ID: 3729166 • Letter: W
Question
Write regular expressions to match the following criteria and only the following criteria. Write regular expressions only, not Ruby code.
(a) Any string that contains an integer comprised of 3n + 1 digits, for n e N for example, these string match: "ur 8", "4002", "Ticket #3435947". These do not: "44th ain't bad.", "div-921", "[10230]"
(b) Any string whose entire contents are a septendecimal (Base-17) literal. Allow for either upper or lowercase letters.
(c) Any string that contains a block of test that begins with $$ and ends with $$. Match only a single block
(d) Any string whose entire contents are one the form CITY, State ZIP. STATE is a two letter state abbreviation. ZIP is either a 5-digit or ZIP+4 ZIP code. Capture the three pieces of information and only those three. For example, matching "Madison, New York 54703-1204" should capture "Madison", "NY", and "54703-1204"
(e) Any string that contains a sequence of space of tab characters at the end of a line. Match the whole sequence Such trialing spaces are a scourge.
Explanation / Answer
a) .*(ddd)*d.*
b) [0-9a-gA-G]+
c) Question not clear
d) [a-zA-Z]+, [a-zA-Z]{2,2} [0-9]{5,5}-[0-9]{4,4}
e) .*( )+
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.