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





Searching for a Match within a String

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

Often, regular expressions are used to search through a text for a substring that matches. Many text editors allow the user to use a regular expression to search through an entire text file for a match. Notepad++ includes this feature. This is useful if you are searching a document for any instance from a set of substrings.

In the applet, search the string for "bell" by clicking the button. The Result box shows where the pattern was found.

Unlike the previous live examples, in this example it is no longer necessary for the entire string to match the RE. The string is searched for a substring that matches the RE. This type of matching corresponds the the find() method of the Java class Matcher. (This will be discussed in chapter 11.)


You have written a brilliant poem about bells. However, you may have misspelled "bells" several times by using the wrong vowel. Devise a regular expression that searches for misspellings of "bells".