Lab 4 - regular expressions

Author

your name goes here

do something with chatgpt. ask chat gpt how to answer the question. then ask using SQL then ask using stringr.

  1. Determine whether a user entered a North American phone number in a common format, including the local area code. Common formats include 1234567890, 123-456-7890, 123.456.7890, 123 456 7890, (123) 456 7890, and all related combinations.

Solution: ^(?([0-9]{3}))?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

Test your solution on the following potential phone numbers:

  1. Validate dates which are in the format mm/dd/yy or mm/dd/yyyy. Allow months to go to 19 and days to go to 39.

Solution: ?[0-9]/[0-3]?[0-9]/([0-9]{2})?[0-9]{2}

Test your solution on the following potential dates:

  1. Check a command line response so that true, t, yes, y, okay, ok, and 1 are all accepted in any combination of uppercase and lowercase.

Solution: ^(1|t(rue)?|y(es)?|ok(ay)?)$

–>> need to figure out about lower and upper case in R / grep()

Test your solution on the following potential responses:

  1. Match numbers that use the comma as the thousands separator and the dot as the decimal separator.

Solution: {1,3}(,[0-9]{3})*.[0-9]+$

Test your solution on the following potential values: