The following problems are trivial to solve using a computer. Since you will be asked to solve such problems in the absence of a computer, we recommend the following. Read the regular expression carefully, write down what you think it matches, and use a computer only to verify your answer.

If you are unsure about a problem, to try out a few experiments with grep or with the `search' command (/) in vi. Remember that grep does not expect you to enter the / delimiters when you enter the regular expression for which to search, but vi does, and that both use case-sensitive searches by default.
  1. Consider the following text, taken from the manpage for a hypothetical UNIX command called flip:
    Flip is a file interchange program that converts text file
    formats between **IX and MS-DOS.  It converts lines ending
    with carriage-return (CR) and linefeed (LF) to lines ending
    with just linefeed, or vice versa.
    If we refer to these lines by number (1 through 4 from top to bottom), then which line(s), if any, match each of the following REs?

    1. /in/
    2. /[R-Z]/
    3. /^[Ff]/
    4. /.$/
    5. /ee*/
    6. /\*/
    7. /lines\{0,\}/
    8. /[Cc].*[Ff]/
    9. /(.\{2\})/
    10. /[Ii][acX][^a-f]/

    Here, a line matches if there is at least one substring in the line that matches the given RE. Also, in the REs above ( and ) characters used alone match themselves, while \( and \) are used for grouping (these are the rules that grep and ex/vi use, while egrep uses the opposite conventions). Also, \{ and \} are special in grep and ex/vi. All of these REs are case-sensitive as well.

  2. In the following the set of full regular expressions, identify all substrings which match each regular expression (without crossing lines, of course) in the four lines listed in the flip text above. You can do this by listing all the matched strings. Remember that regular expressions match the longest possible string. For example, the full regular expression /\(.*\)/ matches the following string:
    (CR) and linefeed (LF)
    Find all possible matches for each of the following full REs:

    1. /F[^ ]+/
    2. /line(s|[^s ]+)/
    3. /v.*e/
    4. /[a-z]*[e.]$/
    5. /\*+/