go to previous page   go to home page   go to next page

Answer:

A[XY]


Practice with Choice

Regular Expression
(Delimit with quotes)
String
(Delimit with quotes)

The above applet checks if strings match the regular expression [wW][hH][yY]. Enter strings in the text box labeled String. Click on the button to see if the string matches the regular expression. Be careful with spaces. If you type why in the string box, it will not match the pattern because of the space at the end of the string.

Enter a new regular expression in the text box labeled Regular Expression. If you enter a badly formed regular expression, an error message will appear in the results box. Here are a few regular expressions and the strings they accept or don't accept:

Regular Expression Matches Non-Matches
ab[xy]cd abxcd abycd abcd abxycd
[oO]wl[sS] owls OwlS owl Owl
tag[- ]line tag line tag-line tagline tag- line

Copy expressions and strings from the table and paste them into the applet to see if they match. Be careful with spaces, however. If something looks like it should match, but does not, see if there are spaces on either end of the RE or the string. Notice that the [- ] of the last RE contains a hyphen followed by a single space.

It is harder than you might think to enter an invalid RE. A random string of characters might look invalid, but might be a valid RE that matches that random string of characters. For example,

]!a!bX]

is a valid RE that matches the string ]!a!bX]


QUESTION 9:

Does [DdoO]g match dog ?