BIO/CS 271 – Introduction to Bioinformatics
CEG333 – Introduction to UNIX
Practice Problems: Regular expressions
1) Write a regular expression that would match the strings: “cat”, “at”, and “t”.
2) Write a regular expression to recognize any string that contains the substring “bob”.
3) Write a regular expression that would match the strings: “cat”, “caat”, “caaat”, “caa…aat”, etc. (strings that start with c, followed by one or more a’s, ending with a t).
4) Write a regular expression that matches the strings: “dog”, “Dog”, “dOg”, “DOG”, “dOG”, etc. (That is, “dog” written in any combination of uppercase or lowercase letters.)
5) Write a regular expression that matches any positive number (with or without a decimal point). Hint: if there is a decimal point, there must be at least one digit following the decimal point. Hint #2: Since the dot “.” Matches any character, you must use \. to match a decimal point.
6) Write a regular expression to match any natural number that doesn’t end in 9.
7) Write a regular expression to match any line with exactly one word. White space (any number of spaces) is allowed before or after the word.
8) Given the regular expression: c(.*)gg(\d*) and the string:
c my dog run gg234and me
What will be the value of \1? What will be the value of \2?
9) List five strings that would match the regular expression: c[abc]+[ ]+k[aeiou]*. List two strings that would not match this regular expression.
Solutions
1) ^c?a?t$ Ex: egrep ‘^c?a?t$’ words
2) bob Ex: egrep ‘bob’ words
3) ^ca+t$
4) ^[dD][oO][Gg]$
5) ^[0123456789]+\(\.[01234567890]+\)?$
6) ^[0123456789]*[012345678]$
7) ^[ ]*[a-zA-Z]+[ ]*$
8) \1 = ‘ my dog run ‘
\2 = ‘234‘
9)
Example Matching strings:
cbba keai
cbc kiu
cc k
Example of strings that do not match:
bob
ted
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- introduction to financial management pdf
- introduction to finance
- introduction to philosophy textbook
- introduction to philosophy pdf download
- introduction to philosophy ebook
- introduction to marketing student notes
- introduction to marketing notes
- introduction to information systems pdf
- introduction to business finance pdf
- introduction to finance 15th edition
- introduction to finance books
- introduction to finance online course