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

Ruby Regular expression http://rubular.com Write the RegExp that matches full wo

ID: 3676347 • Letter: R

Question

Ruby Regular expression

http://rubular.com

Write the RegExp that matches full words for the following: Date format (i.e. 12/7/1968 or 3-21-2000). Complete this problem two different ways, with and without the usage of a back-reference. Negative real numbers (i.e. -1.25, -101.2) Currency values (i.e. dollar 21.05, dollar1.65) Time values (i.e. 12:20AM, 1:08pm) Integers which have one or more occurrences of the digit 7 followed by at least one occurrence of the digit 3 such as 773 and 97223 but not 737 or 772. Note that all occurrences of 7 must precede all occurrences of 3. Two consecutive words which begin with a capital letter (i.e. John Adams, Rocky Balboa). IP Addresses. Note that each octet is in the range 0-255. Suppose your domain are digits 1, 2, & 3. The RegExp should match consecutive digits in descending order (i.e. 1232, 11231). In other words, match the digits and not the entire number. For example, given, 1232 and 11231, the matching should be 32 within the first number and 31 within the second number. Search for lines which begin with a backslash character. Palindromes up to a length of 7 characters such as racecar and hannah.

Explanation / Answer

regex for negative real number:

regex for currency value:

^$?(?=(.*)|[^()]*$)(?(d{1,6}|d{1,3},d{3})(.dd?)?)?$

time value validation:

/^([0-1]d):([0-5]d)s*(?:AM|PM)?$/i

regular expression for two consecutive word begin with a capital letter:

ruby-1.9.2-p0 > %Q{The A-Z Group is a long-established market leader in the provision of information for the global air cargo community, and also for the defence and security sectors through BDEC Limited, publishers of the British Defence Equipment Catalogue and British Defence Industry Directory.}.scan(/([A-Z][w-]*(s+[A-Z][w-]*)+)/).map{|i| i.first}

regular expression for ip address validation each octets is in range of 0-255: