Logic & Computation Regular Expression Worksheet 1

Give a regular expression that specifies the following languages. 1. All strings consisting of only x and y where the first character is an x and the last character is a y. 2. All strings consisting of only a and b but contain the substring abba. 3. All positive integers. 4. All linear equations of the form y = mx + b (m and b positive). This contains things like y = 3x + 6 and y = 134x + 486. 5. All positive integers divisible by 5. 6. All English words (only lowercase) that contain the substring “spb” (such as raspberry). 7. All words that can be typed using only the top row of the keyboard. Describe the language specified by the following regular expressions. 8. (1)(0 | 1)* 9. a*ba*ba* 10. (a*ba*ba*)* 11. a*b*c* 12. (0|1)((0|1)(0|1))* Give a generalized regular expression that specifies the following languages. 13. All email addresses where the use name consists only of lowercase letters followed by a single digit (smith4) and had one of the three extensions: com, net, org [email protected] [email protected] [email protected] 14. Dollar amounts, e.g. $253.12 15. All positive integers that have exactly seven 5’s in a row. 16. All three letter words using lower case letters. Describe the languages specified by the following REs. 17. (Mr)(s?)/. [A-Z][a-z]* 18. /–[^0][0-9]* 19. \/(/+_/+/)// 20. (/(740/) .../-....) | (.../-....) (the alphabet is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})