Exercise 1: Capture the Class Names

Write a regular expression to extract data from the given text.

We'll cover the following


You’re given an input text that contains some data (alphabetical characters only). This data appears between two different types of tags. It appears between either the class tags or the object tags as shown:

  1. <class>Something</class>

  2. <object>SomeOtherThing</object>

Your task is to use a regular expression to extract the data enclosed within the class tags.


Consider the input below:

<class>Hash</class> <object>true</object> <object>nil</object> <class>TrueClass</class>

The output should be:


Try it yourself

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy